Santosh
Santosh

Reputation: 1839

Matlab set param from array

In Matlab, in order to change the value of a block I do

set_param('model/V','Amplitude','100')

and the value of V is 100. But if I do

for i=1:10
     set_param('model/V','Amplitude','P(i)')
     ...
end

The it stores the value of V as P(i). But in order to access the i-th element of the 20-by-1 P matrix, I need to refer to it by P(i). What is my error?

Upvotes: 2

Views: 784

Answers (1)

P0W
P0W

Reputation: 47844

Change the value to string using:-

set_param('model/V','Amplitude',num2str(P(i)) );

Also it will set the value of 'model/V' to P(20) i.e. last one.

You might want to loop through the current blocks too

Something like : (just example)

set_param(['model/V' num2str(i)],'Amplitude',num2str(P(i)) );

for model/V1, model/V2,...model/V20 .

Upvotes: 3

Related Questions