readtable() custom variable names (2024)

345 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

Muhammed Yusuf Aksel am 4 Apr. 2020

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names

Kommentiert: Stephen23 am 18 Mai 2022

Akzeptierte Antwort: Ameer Hamza

I am using the below command to read a csv file into a table called T.

T = readtable("library.csv")

Now, the first row of the csv inludes the column headers, or variable names you can say. However, I want to change those variable names as I want. I have inspected readtable() documentation, but could not find the solution.

How can I do this?

Thanks.

0 Kommentare

-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Akzeptierte Antwort

Ameer Hamza am 4 Apr. 2020

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names#answer_423930

Bearbeitet: Ameer Hamza am 4 Apr. 2020

One way is to change the variable names after reading the file like this.

t = readtable("library.csv");

t.Properties.VariableNames = {'name1', 'name2'}; % names of columns

6 Kommentare

4 ältere Kommentare anzeigen4 ältere Kommentare ausblenden

Stephan Piotrowski am 3 Nov. 2021

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names#comment_1813525

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names#comment_1813525

Certain variable names can cause a nuissance warning that clutters the command window. To avoid this, readtable can be called with "VariableNamingRule","preserve" as detailed in the documentation. But can the variable names in the source data be ignored entirely so that this does not have to be done? Perhaps by calling with ReadVariableNames set to false and DataRange set to 2?

Supriya Gain am 18 Mai 2022

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names#comment_2165010

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names#comment_2165010

In my case readtable automatically generate column header as "VAR". If I do not want to generate that "VAR" what should I do?

Stephen23 am 18 Mai 2022

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names#comment_2165080

"If I do not want to generate that "VAR" what should I do?"

Table columns/variables must have headers. If the header is not imported from a file, the default VAR* is used.

You can specify the header names when importing the file data, or replace them afterwards (see the above answer). What do you expect to see as the header names in your table?

Supriya Gain am 18 Mai 2022

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names#comment_2165825

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names#comment_2165825

Actually I'm converting.xls file to .CSV by using the command 'readtable'. Now in my actual dataset there was no header. But after converting using 'readtable' a default header is coming which is 'Var'. Now I don't want this to come. What should I do?

Walter Roberson am 18 Mai 2022

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names#comment_2165895

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names#comment_2165895

table() objects must have unique names for each variable. It is not possible to create a table() object which does not have variable names.

You can readtable() and pass VariableNames at the time of reading, thereby giving some name of your choice.

You can skip a header by using HeaderLines, 1 and ReadVariableNames, false

Stephen23 am 18 Mai 2022

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names#comment_2165975

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names#comment_2165975

@Supriya Gain: use READCELL and WRITECELL instead.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Steven Lord am 18 Mai 2022

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names#answer_966370

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/515283-readtable-custom-variable-names#answer_966370

If you're using release R2020a or later I would use the renamevars function.

0 Kommentare

-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Kategorien

MATLABLanguage FundamentalsData TypesTables

Mehr zu Tables finden Sie in Help Center und File Exchange

Tags

  • csv
  • table
  • readtable

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.


Translated by readtable() custom variable names (10)

readtable() custom variable names (11)

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

readtable() custom variable names (2024)
Top Articles
Latest Posts
Article information

Author: Pres. Lawanda Wiegand

Last Updated:

Views: 6263

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Pres. Lawanda Wiegand

Birthday: 1993-01-10

Address: Suite 391 6963 Ullrich Shore, Bellefort, WI 01350-7893

Phone: +6806610432415

Job: Dynamic Manufacturing Assistant

Hobby: amateur radio, Taekwondo, Wood carving, Parkour, Skateboarding, Running, Rafting

Introduction: My name is Pres. Lawanda Wiegand, I am a inquisitive, helpful, glamorous, cheerful, open, clever, innocent person who loves writing and wants to share my knowledge and understanding with you.