Convert table and obtain column values

조회 수: 1 (최근 30일)
Collegue
Collegue 2019년 9월 13일
답변: Steven Lord 2019년 9월 18일
Hello, I have this table
Captura.PNG
How can I first generate an array of string and numbers and then replace the '---' with NaN. Finally I would need to get the values of the Var4 and Var 7.
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 9월 13일
Have you check here readtable?
Collegue
Collegue 2019년 9월 13일
Yes I have conberted to table and that is the table that i have obtained.

댓글을 달려면 로그인하십시오.

채택된 답변

Jalaj Gambhir
Jalaj Gambhir 2019년 9월 16일
Hi,
For the particular task one possible solution could be by first converting the table to cell array using table2cell. And then traversing through the structure to search for ‘- -’ and replacing it with NaN
T = cell(CellArray);
for i=1:length(CellArray)
for j= 1:length(CellArray{1})
if ~isequal(CellArray{i,j},'--')
T{i,j} = CellArray{i,j};
else
T{i,j} = NaN;
end
end
end
R = cell2table(T);
And finally access the 4th and 7th column from the table by:
R(:,[4,7])
  댓글 수: 1
Collegue
Collegue 2019년 9월 18일
Thank you very much1!! it works!!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven Lord
Steven Lord 2019년 9월 18일
Use ismissing to locate the missing values (you can tell ismissing what it should consider as a missing value) then use the logical array output to replace the missing values with whatever value you want.
The fact that you're changing the data type (potentially for some but not all of the values of a table variable) could complicate things a bit, but if that's the case show a larger sample of your table (maybe two or three rows that have a missing value and two or three that don't) and we may be able to help you determine how to handle that situation.

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by