필터 지우기
필터 지우기

Exporting variable names and their respective data types to excel

조회 수: 4 (최근 30일)
Wesso
Wesso 2021년 1월 12일
답변: Walter Roberson 2021년 1월 12일
Hi,
I have many tables with different sizes. I am trying to concatenate these tables where the column names match but it seems that their datatypes are different which is yelding errors. Is there a way to export variable names and their respective datatypes of each table to excel in order to see which variables don't have the same data type and change them accordingly?
In other word. I have Matrix M with size of 10,000 x 500. How can I get the datatype of each column in excel?
  댓글 수: 1
Adam Danz
Adam Danz 2021년 1월 12일
편집: Adam Danz 2021년 1월 12일
> Is there a way to export variable names and their respective datatypes of each table to excel in order to see which variables don't have the same data type and change them accordingly?
This suggests that the data are already in Matlab. To get the class of each variable of a table, use,
varClass = varfun(@class,T); % T is a table
There are function that can cast a variable class to a new class such as num2str(), categorical(), etc.
If the Matlab data were created by reading data from a file, fix the problem by reading in the data correctly by specifying the intended class which can be done in all of the tabular read-in functions such as readtable and readcell.

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

답변 (1개)

Walter Roberson
Walter Roberson 2021년 1월 12일
You can get the MATLAB datatypes by using
vt = reshape(varfun(@class, YourTable, 'outputformat', 'cell'), [], 1);
[uvt, ~, g] = unique(vt)
counts = accumarray(g(:), 1);
[uvt, num2cell(counts)] %displays types and counts
[~, mcidx] = max(counts);
not_common_idx = find(g ~= mcidx);
[num2cell(not_common_idx(:)), vt(g(not_common_idx)) %displays variable numbers and type for all but most common

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by