Dear all,
I'm writing a program in Matlab, where all data is first loaded from the file '20.mat'. Then I create a vector with all 20's, to remember the data in that column is from the film '20.mat'. After some scripts, I want to replace one of these column with data from a file-number lower. So for example:
First: A=[20 20 20 20 20]
Replacing place: 4
Load data with number from A(4)-1 = 19, and replace column 4 with the data from column 4 of '19.mat'.
The problem however is that I don't know beforehand with number I have to load, because if in the next step the replacing place is 1, I again need to load data from '19.mat', but if I again have to replace place 4, I have to load '18.mat'. I could write an if-loop for all separate cases, but because there are quite a lot of cases, I was wondering if there is a direct way to do this. Something like load('r.mat'), where r=A(4)-1.
Kind regards, Marjolein

 Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 27 Juil 2015

0 votes

r=sprintf('%d',A(4)-1)
data=load(r)

2 commentaires

Azzi Abdelmalek
Azzi Abdelmalek le 27 Juil 2015
Marjolein commented
Thank you for your response. While implementing the above, I realize I have to both load '19.mat' and 'd19.mat'. It is probably easy to add the 'd' somewhere, but I haven't really found it yet. Can you help me?
Azzi Abdelmalek
Azzi Abdelmalek le 27 Juil 2015
Marjolein commented
Nevermind, I already got it!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Report Generator dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by