How to multiply arrays in struct file with a variable?

7 ビュー (過去 30 日間)
Ahmad Hasnain
Ahmad Hasnain 2018 年 10 月 1 日
回答済み: Ahmad Hasnain 2018 年 10 月 1 日

I have four variables that are known to me, i.e. 'high', 'low' and 'a' and 'b'. I have a mat file, which contains a lot of arrays. I successfully load the array I want. But I want to multiply the arrays with variable 'a' and 'b'.

filename1 = sprintf('Zy%d', low);
c = a * load('Z.mat', filename1);
filename2 = sprintf('Zy%d', high);
d = b * load('Z.mat', filename2);

But I get this answer:

Undefined operator '*' for input arguments of type 'struct'.

How do I multiply the variable with these loaded arrays?

採用された回答

Rik
Rik 2018 年 10 月 1 日
The load functions loads to a struct, where each variable is a field, even when you specify only a single variable. The code below should do the trick.
filename1 = sprintf('Zy%d', low);
temp=load('Z.mat', filename1);
c = a * temp.(filename1);
filename2 = sprintf('Zy%d', high);
temp=load('Z.mat', filename2);
d = b * temp.(filename2);
If you're working on Octave the following syntax might work as well
d = b * load('Z.mat', filename2).(filename2);

その他の回答 (1 件)

Ahmad Hasnain
Ahmad Hasnain 2018 年 10 月 1 日
Thanks. The answer was very helpful.

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by