537 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Callum Clarke am 27 Sep. 2016
Bearbeitet: Leon am 19 Feb. 2024
Akzeptierte Antwort: Peter Perkins
I want to compare data types of each column of a table against a cell array of column header-data type pairs, with the end goal of replacing columns with non-matching data types with the correct ones.
What I have managed so far is a loop that creates another cell array of header-data type pairs. What I need now is a way to compare this array to the 'checklist' array, returning which columns have non-matching data types. There is no guarantee of the table having the same columns or being on the same order as the array it is checked against. I tried ismember() but it just returns a 2xn array of 1s, even for tables that shouldn't match. I think I need to define key/value pairs somehow.
Any suggestions on how to do this, or other methods entirely, are more than welcome!
1 Kommentar -1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
dpb am 1 Jan. 2024
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/304728-getting-data-types-of-table#comment_3014211
Agree, this should be a metadata property of the table and thus directly accessible.
Melden Sie sich an, um zu kommentieren.
Melden Sie sich an, um diese Frage zu beantworten.
Akzeptierte Antwort
Peter Perkins am 3 Okt. 2016
Bearbeitet: Cris LaPierre am 18 Nov. 2022
It seems like you want a list of the table's variable names, a list of the variable's types, and your 2xn cell array of names/types. Use t.Properties.VariableNames and varfun(@class,t,'OutputFormat','cell') to get the first two things.
Then it seems like you'd want to use ismember )both outputs) on the variable names to figure out which are matched in your other list, and where, and then for the ones that do match, compare their types using strcmp.
Hope this helps.
2 Kommentare Keine anzeigenKeine ausblenden
Keine anzeigenKeine ausblenden
dpb am 1 Jan. 2024
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/304728-getting-data-types-of-table#comment_3014216
@Peter Perkins -- I never could figure out why this isn't a member of the table properties stuct, just like .VariableNames; seems like it would be obvious to want/need on occasion; particularly if it is needed to be able to clone a table if one wishes to augment an existing one with some more data.
It goes along with my previous wishes for a function that would append an empty record to an existing table...
Leon am 19 Feb. 2024
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/304728-getting-data-types-of-table#comment_3070298
Bearbeitet: Leon am 19 Feb. 2024
I third that. I'd like this feature too. And I also recently asked about how to add an empty record too! This may be of interest for that:
https://uk.mathworks.com/matlabcentral/answers/2067371-what-is-the-best-way-to-add-empty-rows-to-an-existing-table-to-pre-allocate-for-more-data/?s_tid=ans_lp_feed_leaf
Did you find a better way?
Melden Sie sich an, um zu kommentieren.
Weitere Antworten (1)
Geoff Hayes am 27 Sep. 2016
In MATLAB Online öffnen
Callum - class allows you to determine the class or data type of an object. For example,
>> x = 42;
>> class(x)
ans =
double
This function may be useful in determining the data type of each object in your table.
1 Kommentar -1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Giuseppe Degan Di Dieco am 30 Nov. 2021
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/304728-getting-data-types-of-table#comment_1860589
Thank you Geoff!
The suggested command works also with table variables.
Best!
Melden Sie sich an, um zu kommentieren.
Melden Sie sich an, um diese Frage zu beantworten.
Siehe auch
Kategorien
MATLABLanguage FundamentalsData TypesData Type Identification
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Tags
- matlab
- table
Produkte
- MATLAB
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Es ist ein Fehler aufgetreten
Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asien-Pazifik
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Kontakt zu Ihrer lokalen Niederlassung