Making a for-loop based on a condition for the third dimension of a 3D Array

2 views (last 30 days)
I would like to include "a3" as a condition in the for-loop but cant get it to work. The final form of "AllaMatriser" should be a 24x365x60 where the change from the actuall for-loop should have affact only 30 out of the 60 sheets, where the other 30 would be left unchanged.
Thanks in advanced!
AntalObjekt = 60;
Procent = 0.5;
AntalLadd = fix(AntalObjekt*Procent);
i =11;
b3 = 1:AntalObjekt;
a3 = randsample(b3, AntalLadd);
for i = i
AllaMatriser(m_spotpris==1) = i; % Both AllaMatriser and m_spotpris are 24x365x60 matrices
end

Accepted Answer

Jan
Jan on 18 Aug 2022
Omit strange useless lines like "for i = i".
AntalObjekt = 60;
Procent = 0.5;
AntalLadd = fix(AntalObjekt*Procent);
i = 11;
a3 = randparm(AntalObjekt, AntalLadd);
match = false(size(m_spotpris));
match(:, :, a3) = (m_spotpris(:, :, a3) == 1);
AllaMatriser(match) = i;

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!