Subdivide a cell, based on the number of columns, inside a for loop
Show older comments
Hi! I would like to compact the rows 'char2string1', 'char2string2', ... inside a for loop. How could I do this?
char2string = importdata("char2string.mat");
num_char2string = width(char2string);
Col = 6;
Row = num_char2string/Col;
Row = round(Row,0);
% I would like to compact these rows because they have to depend by 'Col' and 'Row'
char2string_1 = char2string(1,1:Col);
char2string_2 = char2string(1,Col+1:Col*2);
char2string_3 = char2string(1,Col*2+1:Col*3);
char2string_4 = char2string(1,Col*3+1:Col*4);
char2string_5 = char2string(1,Col*4+1:end);
3 Comments
This is what the data actually looks like:
S = load('char2string.mat');
C = S.char2string % storing scalar strings in a cell array is very inefficient. Use a string array instead.
Please show us the exact output that you require from this input data.
Note that storing scalar strings in a cell array is very inefficient and means that you do not get any of the benefits of using a string array. You should use a string array, just as the MATLAB documentation recommends:
Alberto Acri
on 8 Sep 2023
Edited: Alberto Acri
on 8 Sep 2023
Dyuman Joshi
on 8 Sep 2023
How did you obtain the data? Did you get it as output from some code? As @Stephen23 mentions above, storing in that manner is not efficient.
And why do you want to generate Dynamically named variables?
Answers (1)
I don't know what you exactly want but this could be your answer:
for i = 7:-1:1
char2string_(i) = char2string(1,Col*(i-1)+1:Col*i);
end
I don't know what you want to do, what is supposed to come out and also how useful all this is.
Categories
Find more on MATLAB Report Generator 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!