How to import multiple variable starting the same from excel?

2 visualizaciones (últimos 30 días)
Elisa Cohen
Elisa Cohen el 1 de Ag. de 2022
Comentada: Elisa Cohen el 1 de Ag. de 2022
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

Respuestas (2)

dpb
dpb el 1 de Ag. de 2022
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 el 1 de Ag. de 2022
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.

Community Treasure Hunt

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

Start Hunting!

Translated by