Estefania
Estefania

Reputation: 95

Insert variable in a string, matlab

I am analyzing some data and I need to load the information from a file. I wrote a script which contains the following line:

load('../Psychopy/DataPrueba/Estefi_1_datos.mat');

I'm wondering if there's anyway to write something like:

Name=Estefi;
load('../Psychopy/DataPrueba/Name_1_datos.mat');

Because it's data from an experiment, I have to do with 40 people at least and that little change in the script would automatize my work quite a lot.

Upvotes: 0

Views: 755

Answers (1)

Schorsch
Schorsch

Reputation: 7925

You can do it like this:

Name='Estefi'; 
load(['../Psychopy/DataPrueba/',Name,'_1_datos.mat']);

Two things to note:

  1. The variable Name has to be a string (use ')
  2. You have to use square brackets ([]) around the combination of strings and your variable.

Upvotes: 1

Related Questions