How to load my MAT files into a structure

7 次查看(过去 30 天)
I am looking to write a code where the Mat files I import are stacked together. I have started the code like this:
prompt = {'Enter Number of therapists','Enter number of trials' };
dlg_title = 'Input Report Information';
num_lines = 1;
Input = inputdlg(prompt,dlg_title,num_lines);
Therapist_number = char(Input(1));
Trial_number = char(Input(2));
I would like to open the file with the number of therapists listed and then have the number of trials underneath it.
Previously I have used a code which stacked my data but now I would like it stacked in relation to the input number of therapists and trial number. This old section of code is written with a specific number of inputs.
cd(pname)
[filename, pathname, ~] = uigetfile( ...
{ '*.mat','mat-files (*.mat)'}, ...
'Select condition one mat file');
load([pathname filename])
COND_DATE = filename(8:19);
Condition_1 = COND_DATE(1:4);
Condition_1_YEAR = COND_DATE(5:8);
All mat files have a similar title 'COND_DATE' and I have uploaded a sample Mat file. I would like all my data stacked under the 'MEAN' and 'SD' headings. So it will be: MEAN > Therapist 1 > Trial 1 > Trial 2 > Therapist 2 > Trial 1 > Trial 2 * with the possibility to have more therapists & trials depending on the input
  1 个评论
Stephen23
Stephen23 2017-4-10
编辑:Stephen23 2017-4-10
Some comments:
  1. using fullfile is much better than concatenating the filepath and filename.
  2. You should load your data into a variable, rather than directly into the workspace. This then also makes it trivial to create a non-scalar structure directly in a loop when the data is loaded.
  3. load the data first (into a non-scalar structure), then rearrange it, if required.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Variables 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by