How to use variable value as an input to the function?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have the function which takes two arguments:
match(template1 , template2);
I want to save the first and second argument name as a string:
name1 = 'template1'; name2 = 'template2';
And then pass this names into my match function:
match( name1 , name2 )
MATLAB reads it as strings but I want it to be pointers to to template1 and template2. Do you know how to achieve this?
2 Kommentare
dpb
am 31 Jul. 2013
Better back up and describe what end objective is--Matlab is not C so talking about pointers is generally an attempt to implement something as if it were.
Antworten (2)
Walter Roberson
am 31 Jul. 2013
function r = match(t1 , t2)
name1 = inputname(1);
name2 = inputname(2);
r = match_by_name(name1, name2);
end
where match_by_name is your second "match" function.
1 Kommentar
Walter Roberson
am 1 Aug. 2013
nT = length(template);
result = cell(nT,nT);
for K = 1 : nT
result{K,K} = match(template{K}, template{K}); %match against self??
for L = K + 1, nT
result{K, L} = match(template{K}, template{L});
end
end
Richard Brown
am 31 Jul. 2013
You can very probably get away with just passing template1 and template2 themselves (not trying to create references to them).
Matlab won't create copies unless you modify them within your match function.
0 Kommentare
Siehe auch
Kategorien
Mehr zu MATLAB Report Generator 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!