Append Data to Array of Cell

1 Ansicht (letzte 30 Tage)
Georg Söllinger
Georg Söllinger am 11 Nov. 2016
Kommentiert: Georg Söllinger am 12 Nov. 2016
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

Antworten (1)

Walter Roberson
Walter Roberson am 11 Nov. 2016
Bearbeitet: Walter Roberson am 11 Nov. 2016
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 Kommentar
Georg Söllinger
Georg Söllinger am 12 Nov. 2016
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!

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by