フィルターのクリア

How to convert cell to numeric

4 ビュー (過去 30 日間)
José Javier Rubio Rubio
José Javier Rubio Rubio 2020 年 12 月 10 日
コメント済み: Rik 2020 年 12 月 10 日
I have used "readtable" in order to import the same column from several excel. The type of data is "1P", "2P"...."6P". Once MATLAB has imported them, I use table2array to convert the table into an array. After this operation, I'd like to convert the values of each cell into numeric, I mean, convert the cell with 1P into 1, 2P into 2... 6P into 6. I have tried it by using "cell2mat" and then "str2num" but it doesn't work. Anyone can help me?
Thanks in advance.
for i=1:12
energia_activa(:,i)=readmatrix(meses(i),'Range','C2:C2999');
energia_reactiva(:,i)=readmatrix(meses(i),'Range','D2:D2999');
periodo(:,i)=readtable(meses(i),'Range','F2:F2999');
end
potencia_consumida=energia_activa.*4;
%Periodos
periodo_numcar=table2array(periodo);
periodo_num=zeros(2997,12);
for i=1:12
periodo_num=cell2mat(periodo_numcar(:,i));
end
  1 件のコメント
Rik
Rik 2020 年 12 月 10 日
It is not quite clear to me what your data actually is, but why do you expect cell2mat to know what you want? You should write a parsing function that will convert your input char array to a value. Then you can either use a loop or cellfun to process the entire array.
(and don't use str2num, use str2double instead)

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

回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by