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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by