Append Data to Array of Cell
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!