How to import multiple variable starting the same from excel?

1 回表示 (過去 30 日間)
Elisa Cohen
Elisa Cohen 2022 年 8 月 1 日
コメント済み: Elisa Cohen 2022 年 8 月 1 日
Hi, I have an excel file with a lot of colums, and I would like to import all colums that starts similarely and store them in a new matrix like this :
W1_data= readtable(waffer1);
variable = W1_data.Variables;
for i = 1:22
Id = W1_data."DrainI_" + i + "_";
end
This solution does not work and I did not found how to do it.
Thank you

回答 (2 件)

dpb
dpb 2022 年 8 月 1 日
Guessing from the above code snippet, try something like
W1_data= readtable(waffer1);
isDrainVar=startsWith(W1_data.Properties.VariableNames,'Drain');
W1_data=W1_data(:,isDrainVar);
will leave you with the table containing only those variables whos name begins with the string "Drain"

Benjamin Kraus
Benjamin Kraus 2022 年 8 月 1 日
It is hard to offer detailed advice without more information about the structure of the Excel file, and what you mean "this solution does not work". Can you attach your Excel file to the post? What happened when you ran that code? Did you get an error message?
However, generically, my advice for people who want to learn how to import data from a spreadsheet is to use the Import Tool. That tool will show you a preview of your Excel file, and walk you through importing the data. It can even generate code so that you can automate the process later, and it can be very useful in learning the best way to import your specific data from an Excel file.

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by