Renaming parameters in a loop, Comparing Z-Scores

1 Ansicht (letzte 30 Tage)
A
A am 1 Aug. 2011
I have a 48x64x41 array where the dimensions are vertical x horizontal x time. I need to compare the z-score array values for times 1 to 41, ie:
zscores(array(:,:,i)) for i=1:41
and find the time of the array with the greatest values.
I am attempting to use a for loop to assign the array at different times to a parameter:
for i=1:41 z=zscore(array(:,:,i)) end
However, obviously like that z is reassigned each time the loop iterates. What I would like to do is have 41 new "z"'s, corresponding to each time.
i.e
at the end of the for loop there will be z1 through z41, corresponding respectively to zscore(array(:,:,1)) to zscore(array(:,:,41).
I then plan to compare these 41 results to find the time at which the array values are the greatest.
Therefore, my questions are: -How can I change the value of z to be z(i), that is z1 through z41 are the outputs at the end of the for loop?
-Does anyone have a smarter suggestion as to how I can obtain the location time of the greatest array values?
Thank you in advance for your replies!

Akzeptierte Antwort

the cyclist
the cyclist am 1 Aug. 2011
This is better. [I had not realized that zscore() is a MATLAB function.]
arraySize = size(array);
z = zeros(size(array));
for i = 1:41
z(:,:,i) = zscore(array(:,:,i));
end

Weitere Antworten (1)

the cyclist
the cyclist am 1 Aug. 2011
Use a cell array:
% Preallocate
z = cell(41,1);
% Run loop
for i=1:41
z{i} = zscore(array(:,:,i))
end
  3 Kommentare
Walter Roberson
Walter Roberson am 1 Aug. 2011
You did not use the code that the cyclist did. the cyclist used {i} in the assignment, but you used (i) in the assignment.
the cyclist
the cyclist am 2 Aug. 2011
In fairness to Amina, I did several quick edits to this answer, while I (too?) hastily posted answers, before I realized that each "zi" was not expected to be a scalar. In the first incarnation, I did not use cell arrays. [Regardless, my other answer, which was accepted, was better.]

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements 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