필터 지우기
필터 지우기

Difficulty storing Output from Loop (Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 2-by-1)

조회 수: 1 (최근 30일)
This loop works -
for i=1:19
x(find(y(start(i):end(i),:)
==max(y(start(i):end(i),:)))+ (start(i)-1))
end
However, when I try to store the answers in a matrix:
MatrixName = []
for i = 1:19;
MatrixName(i,:) = x(find(y(start(i):end(i),:)
==max(y(start(i):end(i),:)))+ (start(i)-1))
end
I get the following error:
%Unable to perform assignment because the size of the left side is 1-by-1 and
% the size of the right side is 2-by-1.
I think the reason is because in one of the loop iterations there are 2 answers instead of 1 (there are 2 x values when the variable y is at it's max). I can further confirm this because it actually does store the values in a matrix until it gets to that specific trial with 2 values, so that's probably the reason. How would I be able to store these answers?

채택된 답변

Jan
Jan 2019년 7월 4일
편집: Jan 2019년 7월 4일
To store arrays of different sizes, use a cell array:
KMaxSBPFullTime = cell(1, 19);
for i = 1:19
KMaxSBPFullTime{i} = ...
By the way, your code is extremely hard to read. Shorter names would increase the readability:
Result = cell(1, 19);
K5 = KFiveMinTimes;
Kend = KEndMinTimes;
SBP = KetamineRaw.SBP;
Time = KetamineRaw.Time;
for k = 1:19
tmp = SBP(K5(k):KEnd(k),:);
Result{k} = Time(find(tmp == max(tmp)) + K5(k) - 1);
end

추가 답변 (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