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
Utkarsh Belwal 2020-8-31
Please share your code or data points which you are trying to plot.
Utkarsh Belwal
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
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 个评论
Ramo Rafsel
Ramo Rafsel 2020-9-3
编辑:Ramo Rafsel 2020-9-3
Hi Utkarsh, I looked again but I didn't find any mistake in the imported columns. But I guess I will find that out somehow. Otherwise the code and you provided me works wonders.
Just a question since I am not sure if I understand what the split function does:
this line basically just converts the values from the columns to double ones right?
and regarding 1:end-1, it just means the first value until the next-to-last value right?
Thanks a lot in advance for your big support :)
F1 = double(split(string(f1(1:end-1)) , ","));
Utkarsh Belwal
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 CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by