Is z an object here? How to interpret the code?

data = rand(4,4);
means = zeros(1,4);
parfor I = 1:4
% The below usage of structures
% is flagged by Code Analyzer
z.mean = mean(data(:,I));
means(I) = z.mean;
end
disp(means)
Hi all, I found the above code was used to demonstrate incorrect use of parfor construct with MATLAB which can flag compiler errors.
On executing as expected with the code I encountered the an error stating The variable z in a parfor cannot be classified. See Parallel for Loops in MATLAB, "Overview".
what I fail to understand is 1) what is the datatype of z? is it a class an object ??? 2) but the code can be easily modified to handle the problem by replacing z.mean by z and the program runs perfectly. That makes me wonder why using z.mean is required??

답변 (1개)

James Tursa
James Tursa 2017년 9월 13일
편집: James Tursa 2017년 9월 13일

0 개 추천

z is a struct. It has a field named "mean".

댓글 수: 2

but z is not been defined anywhere in the example?
It doesn't explain why a struct is need just to compute and store a mean of a value.
James Tursa
James Tursa 2017년 9월 13일
편집: James Tursa 2017년 9월 13일
I don't know why a struct would be needed for that either. Just use z.
Where did the z.mean code come from in the first place? Did you inherit this code from someone or download it from somewhere? Does it complain if you do a direct assignment:
means(I) = mean(data(:,I));
Is this just an exercise in finding out why parfor doesn't like the struct? (Seems counterproductive to use it for mean calculations)

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

편집:

2017년 9월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by