Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Unable to perform assignment because left and right sides have different number of elements
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to separate a data matrix into multiple separate matrices between zeros, and name them accordingly (e.g., the first "range" of data before the first zero is named "range[1]", the next is named "range[2]", etc.). I was able to do this by storing them in cells, but I need them to be in matrices to do further analysis afterwards, so I am hoping that there is a way to do this separation without converting to cells...any suggestions?
This is my code thus far:
clear all;
close all;
data = [1.431294118; 1.251294118; 1.121294118; 0.051294118; 0.461294118; 0.971294118; 0.481294118; 20.01129412; 14.84870588;13.13129412;0.718705882;0.401294118;0.331294118;0.098705882;0.731294118;0.701294118;0.861294118;0.358705882;0.521294118;0.291294118;0.138705882;11.72129412;7.618705882;2.528705882;1.611294118;0.401294118;0.601294118;0.121294118;0.051294118;0.348705882;0.211294118;0.241294118;0.168705882;0.218705882;4.981294118;15.22870588;2.028705882;0.621294118;1.391294118;1.001294118;0.131294118;1.101294118;0.081294118;0.488705882;1.321294118;];
thresh_data = 1.4;
data(data < thresh_data) = 0;
array_length = length(data);
sample = array_length;
k = 1;
for i = 1:array_length
if (data(i) ~= 0)
range(k) = [range(k), [data(i)]];
elseif (data(i) == 0)
k = k + 1;
end
end
댓글 수: 0
답변 (1개)
Jan
2019년 6월 7일
편집: Jan
2019년 6월 7일
range(k) = [range(k), [data(i)]];
This cannot work, because range(k) is a scalar, but [range(k), [data(i)]] has 2 elements.
By the way, there is no need for square brackets around data(i).
I do not know, what "the first zero is named "range[1]"" means. Maybe you mean a cell array:
k = 1;
range = {};
for i = 1:array_length
if data(i) ~= 0
range{k} = {[range{k}, data(i)]};
else % if data(i) == 0
k = k + 1;
end
end
If this is wanted, there are more efficient methods.
댓글 수: 1
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!