필터 지우기
필터 지우기

Append Data to Array of Cell

조회 수: 1 (최근 30일)
Georg Söllinger
Georg Söllinger 2016년 11월 11일
댓글: Georg Söllinger 2016년 11월 12일
Hi Guys, Again I need your help. Due to any reason I cannot append data to an array in a cell within every round of a for-loop. I'd like to do the following, what should actually work, if looking at help:
R{i,7}(:,1) = [R{i,7}(:,1); (ceil(R{i,1}(j,10)/increment)*increment :increment:floor(R{i,1}(j+1,10)/increment)*increment )'; R{i,1}(j+1,10)];
Matlab throws the error Subscripted assignment dimension mismatch. So I tried the following, but the same error appears.
R{i,7}(:,1) = vertcat(R{i,7}(:,1), (ceil(R{i,1}(j,10)/increment)*increment :increment:floor(R{i,1}(j+1,10)/increment)*increment )', R{i,1}(j+1,10));
Can anyone help me with my problem? Thanks in advance!
Georg

답변 (1개)

Walter Roberson
Walter Roberson 2016년 11월 11일
편집: Walter Roberson 2016년 11월 11일
You cannot increase the number of rows in a variable by using
variable(:, column) = more_data_than_before
When you have an existing array, the : index in the first position expands to 1 : size(existing_array,1) -- a definite size, and you cannot store more data than that there.
It is only when you are storing to an array that has not been initialized that you can use : and have it build the array as big as required.
You will need to use:
newdata = [(ceil(R{i,1}(j,10)/increment)*increment :increment:floor(R{i,1}(j+1,10)/increment)*increment )'; R{i,1}(j+1,10)];
R{i,1}(end+1:end+size(newdata,1), 1) = newdata;
Note that if R{i,1} has more than one column, this would put 0 in those columns in the expanded rows.
  댓글 수: 1
Georg Söllinger
Georg Söllinger 2016년 11월 12일
Hello Mr. Roberson,
Thanks for your answer, this solution works!! Indeed, it was also my guess, that it s the :, who causes trouble...
Thanks again, best wishes!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by