Adding 3 Frequency curves into an existing plot.

2 visualizaciones (últimos 30 días)
Ramo Rafsel
Ramo Rafsel el 14 de Oct. de 2020
Comentada: Ramo Rafsel el 21 de Oct. de 2020
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!

Respuesta aceptada

Seth Furman
Seth Furman el 16 de Oct. de 2020
Editada: Seth Furman el 16 de Oct. de 2020
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 comentarios
Seth Furman
Seth Furman el 18 de Oct. de 2020
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]))
Ramo Rafsel
Ramo Rafsel el 21 de Oct. de 2020
Thanks a lot for the help. The problem has been solved.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by