MATLAB Answers

0

Convert String array into Cell array

Asked by Michael Williams on 15 Mar 2018
Latest activity Answered by Raymond MacNeil on 14 Nov 2019 at 9:21
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;

  0 Comments

Sign in to comment.

2 Answers

James Tursa 님의 답변 15 Mar 2018
 채택된 답변

Is this the conversion you need?
result = arrayfun(@(x)char(varNames(x)),1:numel(varNames),'uni',false);

  1 Comment

Thanks, that worked perfectly. I had tried {result = char(varNames)}, but that gave me a character array.

Sign in to comment.


Raymond MacNeil 님의 답변 14 Nov 2019 9:21

Yes, this also helped me. Thanks a lot.

  0 Comments

Sign in to comment.