forming matrices depending on file name

조회 수: 4 (최근 30일)
Emilia Simonian
Emilia Simonian 2020년 10월 29일
답변: Jemima Pulipati 2020년 12월 14일
I have matlab files in a folder and there are, for example, several that have file names that start with M1, several that start with M9, several that start with M13, etc. I want to group the ones that start with the same letter and number into the same matrix and create separate matrices for different file names.
What matlab functions can I use to do this using for loops????
Thank you for your help in advance!
  댓글 수: 3
Emilia Simonian
Emilia Simonian 2020년 10월 29일
And how could I do that? Sorry if this is a dumb question but I’m new to Matlab so I’ve just started learning these things.
Rik
Rik 2020년 10월 29일
If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).
Otherwise have a read here and here. It will greatly improve your chances of getting an answer (or find one on your own).

댓글을 달려면 로그인하십시오.

답변 (1개)

Jemima Pulipati
Jemima Pulipati 2020년 12월 14일
Hello,
From my understanding, you want to retrieve all the files which start with a particular string into one structure.
You can use the dir() to list the files and folders which match a particular name.
Example:
cd myfolder
s1 = dir ('M1*.m');
s2 = dir('M2*.m');
This code returns all the matlab files which start with 'M1' inside the folder 'myfolder' into a struct array 's1'. Similarly, all the files which start with 'M2' are retrieved into 's2' struct array.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by