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

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 27 日

0 投票

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

2 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 27 日
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 2015 年 7 月 27 日
Marjolein commented
Nevermind, I already got it!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB Report Generator についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by