How do I convert table data to double to manipulate them?

2,406 ビュー (過去 30 日間)
Fernando De Ita
Fernando De Ita 2017 年 12 月 2 日
コメント済み: Peter Perkins 2023 年 9 月 28 日
I extracted data from a table, when I get an element it comes as table format but when trying to make some operations like multiplication there is an error, is there any direct command or a series of steps? Can you help please
  3 件のコメント
Stephen23
Stephen23 2021 年 8 月 25 日
編集済み: Stephen23 2021 年 8 月 25 日
"I extracted data from a table, when I get an element it comes as table format but when trying to make some operations like multiplication there is an error, is there any direct command or a series of steps?"
You could use TABLE2ARRAY, but by far the simplest and most efficient approach is to just use the correct indexing using curly braces to access the table content (not parentheses which returns another table, which is what you did).
The different types of indexing are clearly explained in the documentation:
Peter Perkins
Peter Perkins 2021 年 11 月 8 日
This new example goes even further into indexing and the topic of "doing math on data stored in a MATLAB table":
It's a new-for-R2021b example, but doesn't require the latest MATLAB for anything (most anything?) it covers.

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

採用された回答

Star Strider
Star Strider 2017 年 12 月 2 日
I would use the table2array (link) function. It will put your table into a double array, so you can do whatever you want with it then.
  5 件のコメント
Adish
Adish 2022 年 11 月 3 日
awesome
Peter Perkins
Peter Perkins 2023 年 9 月 28 日
In recent versions of MATLAB, tables and timetables support many element+wise and reduction math operations:
t1 = table([1;2;3],[4;5;6]);
sum(t1,1)
ans = 1×2 table
Var1 Var2 ____ ____ 6 15
t2 = table([7;8;9],[10;11;12]);
t1 + t2
ans = 3×2 table
Var1 Var2 ____ ____ 8 14 10 16 12 18

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

その他の回答 (3 件)

Peter Perkins
Peter Perkins 2017 年 12 月 19 日
The answer might be as simple as something like T.Z = T.x .* T.y. Without more information, hard to tell.

Roger Breton
Roger Breton 2021 年 3 月 8 日
編集済み: Roger Breton 2021 年 3 月 8 日
It does not work for me : all I want is to be able to import a range from Excel, and all I get is a "Table" on which I can't do any operation?
  3 件のコメント
Roger Breton
Roger Breton 2021 年 3 月 9 日
Thank you so much for extending your kind help, Peter.
Yes, all my data is numieric, doubles, in fact. It's just that I'm totally "green" with regards to MatLab data types. I think I used the table2array function to "convert" the data. Once converted, I was able to carry my "normal" arithmetic operation. I really have to give myself the time to learn Matlab...
Stephen23
Stephen23 2021 年 8 月 25 日
If you just need a numeric matrix, why are you importing the data as a table? Use REDAMATRIX instead.

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


Arshey Dhangekar
Arshey Dhangekar 2021 年 7 月 7 日
Hello I have csv data of 18 columns and want to convert into double
so instead of writing 18 str2double code how can I convert all the 18 columns in short line of code
Temp.x310_Ambient__C_ = str2double (Temp.x310_Ambient__C_);
  3 件のコメント
Mohsin Munir
Mohsin Munir 2021 年 8 月 25 日
I have data in excel. there are some coulmns having inputs. I want if i multiply two columns in matlab then the next column to be added in the same sheet rather than a new file in workspace. can anybody help me in this problem
Peter Perkins
Peter Perkins 2021 年 11 月 8 日
1) Post a new question, don't ask a question in a reply to someone else's question.
2) This example may be of help for the topic of "doing math on data stored in a MATLAB table":
It's a new-for-R2021b example, but doesn't require the latest MATLAB for anything (most anything?) it covers.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by