필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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
Walter Roberson
Walter Roberson 2021년 8월 12일
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 2021년 8월 12일
What line is giving the error message?
Could you attach your files as .m files for testing for special characters or misspelled words?

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by