Create and assign variable in function
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello I have a function and I pass in a row vector with different values and I want to take those values and assign variables that I use throughout my function to those specific values and also make them global to be used in other functions
examples
function [] = example1(theta)
if (nargin<1)
theta = zeros(1,28)
sym('j%d',size(theta)%I also tried genvarname({'j'})
for i=1:length(theta)
j{i} = theta(i);
end
else
sym('j%d',size(theta)%I also tried genvarname({'j'})
for i=1:length(theta)
j{i} = theta(i);
end
end
global j1 j2 ....j28 %is there a better way to do this line?
j1
j2
.
.
j28
When I run the function it says that j1-j28 are undefined, what I am expecting is it to print out j1 = 0 -j28 = 0 if I didn't put in any arguments and j1 = 5 - j28 = 7 if I entered values in for theta
and also I want to be able to use j1-j28 in another function
function exmaple2()
plot(sin(j1))
end
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Performance and Memory finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!