フィルターのクリア

Subdivide a cell, based on the number of columns, inside a for loop

3 ビュー (過去 30 日間)
Alberto Acri
Alberto Acri 2023 年 9 月 8 日
コメント済み: Dyuman Joshi 2023 年 9 月 8 日
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 件のコメント
Alberto Acri
Alberto Acri 2023 年 9 月 8 日
編集済み: Alberto Acri 2023 年 9 月 8 日
Hi @Stephen23, I want to get the variables 'char2string_1', 'char2string_2',...,'char2string_#' (as reported in my question) as the end result.
However, in this case the values of 'char2string_#' depend on Col=6. I would like to generalize what I wrote, with a for loop for example, so that I can get a similar result with a different value of Col.
For example, for Col=4 I should get this:
char2string = importdata("char2string.mat");
num_char2string = width(char2string);
Col = 4;
Row = num_char2string/Col;
Row = round(Row,0);
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:Col*5);
char2string_6 = char2string(1,Col*5+1:Col*6);
char2string_7 = char2string(1,Col*6+1:Col*7);
In the case of Col=4, the values of 'char2string_#' are 7, while in Col=6 the values of 'char2string_#' are 5.
I would like to compact the rows with 'char2string_#' and get them directly from a for loop for example.
Dyuman Joshi
Dyuman Joshi 2023 年 9 月 8 日
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?

サインインしてコメントする。

回答 (1 件)

Julian
Julian 2023 年 9 月 8 日
編集済み: Julian 2023 年 9 月 8 日
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.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by