getting a cell array of string into a matrix or table Matlab -
i'm gathering information calculations performed on data , stored arrays. have info these data coming text file , contains strings.
the strings text files got saved {} cell array of strings such as:
strings={'s1' 's2' 's3'}; a=[1 2 3] what strings , arrays contain generated based on few conditionals data present in text file data have in matlab through loop doing things that:
srings{e}=blablahfromsomewhere{e} a(e)=othernumericalblahblahfromsomwehre(e+6) ultimately want joint table. this:
t=[a(:) strings(:)] but i'm facing following error:
error using horzcat dimensions of matrices being concatenated not consistent. can help? don't want transform strings integers because content of string handier have in output in running analysis.
thanks :)
code
strings={'s1' 's2' 's3'}; a=[1 2 3]; outputfile = 'output.txt'; %%// code horziontally concatenate result in nx2 cell array out = [num2cell(num2str(a,'%d')') strings'] %%// write outputfile - method 1 out = out'; fid = fopen(outputfile,'w'); fprintf(fid, '%s\t%s\n', out{:}); fclose(fid); %%// write outputfile - method 2 %%// create text file , clear out of content. needed, otherwise %%// xlsread initializing csv files weird characters %% dlmwrite(outputfile,''); %%// write csv file using xlsread %xlswrite(outputfile,out) %%// verify type(outputfile) output
out = '1' 's1' '2' 's2' '3' 's3' 1 s1 2 s2 3 s3
Comments
Post a Comment