Plotting a curve from 2 excel columns
4 次查看(过去 30 天)
显示 更早的评论
I have two imported columns from Excel, the first one contains the time in HH:MM:SS Format in which the values in the second column were saved. I want to plot the columns against each other and form a curve with the time on the x-axis and the values on the y-axis, but I only get a figure with lines. Is there any code line that I can use to reshape the plotted line into a curve?
3 个评论
Utkarsh Belwal
2020-8-31
Thanks for sharing the code. I can't find anything wrong with the code so if possible can you share the Excel files that you are using, that would be really helpful.
采纳的回答
Utkarsh Belwal
2020-9-1
Thanks for sharing the tables.
After looking into the tables shared by you, I can see that the columns f1, f2 and f3 has two values in each cell separated by comma. In the code you are not separating these values before plotting, that is why your plots are not matching and giving error. I have used split function to separate these values and after splitting used the first colmumn for plotting, look into the documentation of split for more information. Below is your code with few modifications to plot frequencies correctly,
dimtime= H2BLSENSOR_MeanVoltDim.time; %Dimtime in [HH:MM:SS]
dimavg= sum(dim)/size(dim,1); %Average Value of dim in [V].
bll = H2_BLSENSOR_MeanVoltBll.Value; %bll variable column in [v]
blltime= H2_BLSENSOR_MeanVoltBll.time;%blltime in [HH:MM:SS]
bllavg=sum(bll)/size(bll,1); %Average Value of bll in [V]
timef1=H2_BLSENSOR_MeanVoltBll1.timef1; %Time Column for the 1st frequency interval.
timef2=H2_BLSENSOR_MeanVoltBll2.timef2; %Time Column for the 2nd frequency interval.
timef3=H2_BLSENSOR_MeanVoltBll3.timef3; %Time Column for the 3rd frequency interval.
f1=H2_BLSENSOR_MeanVoltBll1.f1; %1st frequency intervall
f2=H2_BLSENSOR_MeanVoltBll2.f2; %2nd frequency intervall
f3=H2_BLSENSOR_MeanVoltBll3.f3; %3rd frequency intervall
v1=H2_BLSENSOR_MeanVoltBll1.Value;%Voltage Value 1
v2=H2_BLSENSOR_MeanVoltBll2.Value;%Voltage Value 2
v3=H2_BLSENSOR_MeanVoltBll3.Value;%Voltage Value 3
nexttile
F1 = double(split(string(f1(1:end-1)) , ","));
F1 = F1(:,1);
plot(timef1(1:end-1),F1);
xticks([timef1(1) timef1(end-1)]);
yticks([F1(1) F1(end-1)]);
nexttile
F2 = double(split(string(f2(2:end-1)) , ","));
F2 = F2(:,1);
plot(timef2(2:end-1),F2);
xticks([timef2(2) timef2(end-1)]);
yticks([F2(2) F2(end-1)]);
nexttile
F3 = double(split(string(f3(1:end-1)) , ","));
F3 = F3(:,1);
plot(timef3(1:end-1),F3);
xticks([timef3(1) timef3(end-1)]);
yticks([F3(1) F3(end-1)])
nexttile
plot(dimtime,dim)
hold on
plot(xdim,[dimavg dimavg],'r-','LineWidth',1);
xticks([dimtime(1) dimtime(end)]);
title('H2BLSENSOR_ MeanVoltDim [V]');
grid on
hold off
I am getting this figure as an output:
Last plot is not coming because you have not shared H2_BLSENSOR_MeanVoltBll table.
DISCLAIMER: These are my own views and in no way depict those of MathWorks.
4 个评论
Utkarsh Belwal
2020-9-3
编辑:Utkarsh Belwal
2020-9-3
Split function splits a string into multiple strings at delimiters. In this case the delimiter is ',' so first the code converts each cell to string so that we can split them and the double outside converts string back to double.
Yes you are right regarding 1:end-1, I used to it because the last cell has only 1 value so split function was giving error.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!