Global variable used in a function invoked by structfun not found / in workspace

1 visualización (últimos 30 días)
I want to plot the fields of a struct, but instead of clotting all the data from the plot on the same abscissa values i want them to be plotted "sequentially".
Therefore i created a global variable time_vector which has the length of the sum of all fields lenghts in the struct. In the function plot_w_time, which is invoked by structfun, i remove the number of entries equal to length(phases_field) which is the length of the field to be plotted, from the beginning of the time vector.
This should result in the next field to be plotted at the end of the first field, as the abscissa values continue where the further ones ended.
At this point i get the errorr:
"Unrecognized function or variable 'time_vector'."
global time_vector
time_vector = time_var;
hh = figure('Name', 'R-LOESS filtered data final');
hold on
structfun(@plot_w_time, phases_struct_loess_filtered,'UniformOutput', false);
grid on
darkBackground(hh, [0.5 0.5 0.5]);
title('IIR-HP and R-LOESS filtered data')
function plot_w_time(phases_field)
global time_vector
plot(time_vector(1:length(phases_field)), phases_field)
time_vector = time_vector(length(phases_field):length(time_vector));
end
  2 comentarios
Walter Roberson
Walter Roberson el 12 de Ag. de 2021
Side note:
time_vector = time_vector(length(phases_field):length(time_vector));
Should be
time_vector = time_vector(length(phases_field)+1:end);
This will not affect the error you are getting, though.
Walter Roberson
Walter Roberson el 12 de Ag. de 2021
What line is giving the error message?
Could you attach your files as .m files for testing for special characters or misspelled words?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Structures 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!

Translated by