Append Data to Array of Cell

3 ビュー (過去 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 Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by