フィルターのクリア

How to convert a cell array of strings to numerical values I can plot?

2 ビュー (過去 30 日間)
Alejandro
Alejandro 2014 年 7 月 28 日
コメント済み: SimonD 2019 年 3 月 20 日
I'm importing data of temperature and magnetic moment and the data import tool imports my selection as a cell array of strings when it has numerical data as you can see in the attached files.
So far I've tried to plot the cell arrays using
plot(Temperature,moment)
plot(Temperature(:,1),moment(:,1))
but it doesn't work because they are strings, not numbers.
So I tried cell2mat and then tried plotting the results and it didn't work either and this time I'm confused as to why it didn't work. In any case, I open up my converted cell2mat variables and I just copy paste the numerical values and paste them into another manually created matrix and this time it works, but this seems a very annoying and frankly ineffective way of plotting my data since I have several data sets that I need to look over.
I've also tried
num2str('Temperature(:,1)')
hoping that this would convert the strings to numbers but it didn't work either.
What's the fastest way to import my data and plot it?

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 7 月 28 日
T=str2double(Temperature);
M=str2double(moment);
plot(T,M)
  2 件のコメント
Alejandro
Alejandro 2014 年 7 月 28 日
Thank you this works! I still find it weird that str2num does not work in this instance.
SimonD
SimonD 2019 年 3 月 20 日
Yes, thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by