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

조회 수: 1 (최근 30일)
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

채택된 답변

Jan
Jan 2022년 8월 18일
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;

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by