Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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 Kommentare
Walter Roberson
Walter Roberson am 12 Aug. 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 am 12 Aug. 2021
What line is giving the error message?
Could you attach your files as .m files for testing for special characters or misspelled words?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by