How do I convert table data to double to manipulate them?
이전 댓글 표시
I extract data from a table. When I retrieve an element, it is in table format, but I encounter an error when attempting to perform operations like multiplication. Is there a direct command or a series of steps to address this issue?
댓글 수: 3
Jan
2017년 12월 2일
Please post any details: An example input, the code you use and the complete error message. Then writing an answer requires less guessing, what you are doing.
"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
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.
채택된 답변
추가 답변 (3개)
Peter Perkins
2017년 12월 19일
0 개 추천
The answer might be as simple as something like T.Z = T.x .* T.y. Without more information, hard to tell.
Roger Breton
2021년 3월 8일
편집: Roger Breton
2021년 3월 8일
0 개 추천
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
Peter Perkins
2021년 3월 9일
Tables are containers for mixed-type data, which is why they don't support "math". You haven't said anything about what you have in the spreadsheet or what you want to do with it. Maybe all your data are all numeric. The syntax I suggested might be what you are looking for to do your operation, or maybe you want to use table2array as SS suggested. Hard to say with no information.
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...
Arshey Dhangekar
2021년 7월 7일
0 개 추천
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
Peter Perkins
2021년 7월 27일
1) Post a new question, don't ask a question in a reply to someone else's question.
2) Try varfun or convertvars.
3) Get to the root cause and figure out why your numeric spreadsheet is being read in as text.
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
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.
카테고리
도움말 센터 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!