How to plot cell datatype in MATLAB
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hassan Rizvi
el 8 de Nov. de 2022
Comentada: Star Strider
el 9 de Nov. de 2022
Hello!
I am here importing data from an Excel file in my workspace. I used readtable command and later convert it into array by using str2array and as a result of this I get cell datatype which has all the correct values. the Excel file contain four variables; Date,Wind speed, Wind angle, Wind power. I also used xlsread function but the output is only 1D array and the remaining arrays were ignored by MATLAB.
data=readtable('sotavento.xlsx');
data=str2array(data);
now, I made a separate 1D array for each variables so that it can be plotted against each other to check the correlation between the given variables.
speed=data(5:end,2); % first 4 points are empty so we discarded.
date=data(5:end,1);
The problem is that I can't plot cell datatype like the way we can plot double etc.
(Note:- the dataset in Excel file may look abnormal as it is quite messy but we are working on it, the main concern is cell datatype plot)
0 comentarios
Respuesta aceptada
Star Strider
el 8 de Nov. de 2022
I would simply stay with readtable and go from there.
Here are two options for plotting the data —
data = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1186153/sotavento.xlsx', 'VariableNamingRule','preserve')
VN = data.Properties.VariableNames;
figure
plot(data.date, data.(VN{2}), 'DisplayName',VN{2})
hold on
plot(data.date, data.(VN{3}), 'DisplayName',VN{3})
plot(data.date, data.(VN{4}), 'DisplayName',VN{4})
hold off
legend('Location','best')
figure
subplot(3,1,1)
plot(data.date, data.(VN{2}))
grid
title(VN{2})
subplot(3,1,2)
plot(data.date, data.(VN{3}))
grid
title(VN{3})
subplot(3,1,3)
plot(data.date, data.(VN{4}))
grid
title(VN{4})
.
4 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

