Adding 3 Frequency curves into an existing plot.

I have written the following code to plot the time, value and the average line of a variable.
I have 3 different frequency intervalls ( see the matlab file of the 3 frequency ranges) that I would like to add into the plot of the value. I already tried but I get an error that I can't plot them since they all should have the same length (or better said: They do not have the same number of rows on their columns).
Is it possible to plot 3 different frequency columns with times despite the length differences?
See the plot in which I'd like to add the 3 frequency curves.
avg_var = sum(var.Value)/size(var.Value,1);
value_var= var.Value;
time_var = var.time;
var_fb1=var_f1.fr; %first frequency range
var_timefb1=var_f1.time; %time values of the first frequency range
var_timefb1 = duration(string(var_timefb1));
var_fb1 = double(split(string(var_fb1(1:end-1)) , ","));
nexttile
plot(time_var,value_var);
xticks([time_var(1) time_var(end-1)]);
yticks([min(value_var) max(value_var+1)]);
hold on
plot([time_var(1) time_var(end-1)],[avg_var avg_var],'r-','LineWidth',2);
title('E1_ ABD_ FoamEventCnt')
xlabel('Uhrzeit in [HH:MM:SS]')
hold off
I have already once plotted a frequency but with no other values, and the code looked like this (this has nothing to do with the code above. Just to show how it worked, with the help of the people here on this forum:
nexttile
Fd1 = double(split(string(fdim1(1:end-1)) , ","));
Fd1 = Fd1(:,1);
dimavg=dimavg(:,1);
timefdim1 = duration(string(timefdim1));
plot(timefdim1(1:end-1),Fd1);
xticks([timefdim1(1) timefdim1(end-1)]);
hold on
plot([timefdim1(1) timefdim1(end-1)],[dimavg dimavg],'b-','LineWidth',2);
title('dimfrequency 1')
xlabel('Uhrzeit in [HH:MM:SS]')
ylabel('Frequenzintervall 150kHz - 80 MHz')
hold off
But I would like to find out how to plot all the 3 curves in a full plot already.
I would appreciate any help! Thanks a lot in advance!

 채택된 답변

Seth Furman
Seth Furman 2020년 10월 16일
편집: Seth Furman 2020년 10월 16일
I'm a little unclear on the question. It sounds like the question is: "Can I plot vectors of different lengths on the same axes?" to which the answer is: "Yes, just call plot multiple times using the hold function."
plot(1:10,1:10);
hold on
plot(3:5,[5 4 3]);
plot(5:7,7:9);
hold off

댓글 수: 5

It doesnt work somehow. Maybe because the length of the columns are not same long?
What is the exact error message you are getting?
I get the the following error everytime: " Vectors must be the same length". So I thought maybe because the columns of the Frequencies do not have the same number of rows. But I am not sure.
Verify that the x and y vectors passed into plot always have the same length. If they do not, then plot will fail with that error message because there needs to be a 1-to-1 mapping between x and y values.
Specifically, please verify that the following two statements return true.
all(size(time_var)) == all(size(value_var))
all(size([time_var(1) time_var(end-1)])) == all(numel([avg_var avg_var]))
Thanks a lot for the help. The problem has been solved.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

질문:

2020년 10월 14일

댓글:

2020년 10월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by