Clear Filters
Clear Filters

Append Data to Array of Cell

1 view (last 30 days)
Georg Söllinger
Georg Söllinger on 11 Nov 2016
Commented: Georg Söllinger on 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

Answers (1)

Walter Roberson
Walter Roberson on 11 Nov 2016
Edited: Walter Roberson on 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 Comment
Georg Söllinger
Georg Söllinger on 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!

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!