フィルターのクリア

Converting Cell Arrays to Strings

2 ビュー (過去 30 日間)
Rohan Khadatkar
Rohan Khadatkar 2012 年 5 月 25 日
I am trying to convert a cell array to string. Got stuck in this.
[num_data,headers]=xlsread(Excel_file_name,Worksheet_name,range_select);
len_headers=max(size(headers));
for var=1:len_headers
var
dummy=headers(var)
eval(strcat(dummy,'=genvarname(headers{var});'));
eval(strcat(dummy,' = num_data(:,var);'));
end
Variable definitions:
But this is giving an error as eval() accepts only strings. dummy remains a 1x1 cell array and after using strcat, the final output of strcat also remains a cell array.
The problem is of converting a cell array to a pure string.

採用された回答

Jan
Jan 2012 年 5 月 25 日
Avoid eval(). There is a nicer, faster and more reliable method always.
[num_data, headers] = xlsread(Excel_file_name,Worksheet_name,range_select);
len_headers = length(headers); % Not MAX(SIZE())
for ivar = 1:len_headers % Do not shadow builtin function VAR
name = genvarname(headers{ivar});
Data.(name) = num_data(:,var);
end
  1 件のコメント
Rohan Khadatkar
Rohan Khadatkar 2012 年 5 月 25 日
Thanks Jan. The struct works fine. This seems to be a much better way also. Again, thanks for the help.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 5 月 25 日

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by