Convert String array into Cell array

259 ビュー (過去 30 日間)
Michael Williams
Michael Williams 2018 年 3 月 15 日
回答済み: Tarek Bekir 2020 年 9 月 5 日
I am running simulations for 16 weather stations and saving 3 simulated temperature measurements at each station. I created a large table (11000x48000) to hold simulations. I want to name each of the columns something descriptive. I was able to get the names I want into a 1x48000 string array, but I believe I have to convert it into a 1x48000 cell array to work.
varNames = join([repmat('Sim_',3*1000*16,1),(reshape(repmat(1:1000,3*16,1),[],1)),...
repmat("_Station_",3*1000*16,1),(reshape(repmat(1:16,3,1000),[],1)),...
reshape(repmat({'_Max', '_Min', '_Avg'},1000*16,1)',[],1)], "")';
simTable.Properties.VariableNames = varNames;

採用された回答

James Tursa
James Tursa 2018 年 3 月 15 日
Is this the conversion you need?
result = arrayfun(@(x)char(varNames(x)),1:numel(varNames),'uni',false);
  1 件のコメント
Michael Williams
Michael Williams 2018 年 3 月 15 日
Thanks, that worked perfectly. I had tried {result = char(varNames)}, but that gave me a character array.

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

その他の回答 (2 件)

Tarek Bekir
Tarek Bekir 2020 年 9 月 5 日
You can use cellstr (array)
For example
tt=["apple";"orange";"banana"];
bb={};
bb=cellstr(tt);
tt
bb
tt =
3×1 string array
"apple"
"orange"
"banana"
bb =
3×1 cell array
{'apple' }
{'orange'}
{'banana'}

Raymond MacNeil
Raymond MacNeil 2019 年 11 月 14 日
Yes, this also helped me. Thanks a lot.

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by