Globalize a matrix with variable elements

2 visualizzazioni (ultimi 30 giorni)
Ismaeel
Ismaeel il 22 Mar 2015
Commentato: Ismaeel il 22 Mar 2015
Hi...
Does Matlab allows to globalize matrix of elements using global function?
I have more than one function file and I want to put the constant values in matrices in one file and globalize it to the other files.
Thanks in advance

Risposta accettata

Jan
Jan il 22 Mar 2015
Modificato: Jan il 22 Mar 2015
You can create a function for this:
function x = IC(i1, i2)
IC = [1.04 0 .716 .27 0 0; ...
1.025 9.3 1.63 0.067 0 0; ...
1.025 4.7 .85 -.109 0 0; ...
1.026 -2.2 0 0 0 0; ...
0.996 -4 0 0 1.25 .5; ...
1.013 -3.7 0 0 .9 .3; ...
1.026 3.7 0 0 0 0; ...
1.016 .7 0 0 1 .35; ...
1.032 2 0 0 0 0];
x = IC(i1, i2);
Now "IC(2,3)" replies the desired element.
  3 Commenti
per isakson
per isakson il 22 Mar 2015
Yes, it must be a separate file. The name of the function is IC. Excluding &nbsp ; ... &nbsp will save you some typing
function x = IC(i1,i2)
buf = [ .04 0 .716 .27 0 0
1.025 9.3 1.63 0.067 0 0
1.025 4.7 .85 -.109 0 0
1.026 -2.2 0 0 0 0
0.996 -4 0 0 1.25 .5
1.013 -3.7 0 0 .9 .3
1.026 3.7 0 0 0 0
1.016 .7 0 0 1 .35
1.032 2 0 0 0 0 ];
x = buf(i1,i2)
end
Ismaeel
Ismaeel il 22 Mar 2015
It is really helpful, thank you Jan. You save me much time and efforts.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by