Azzera filtri
Azzera filtri

sending 'result' as an input to a function

1 visualizzazione (ultimi 30 giorni)
Muazma Ali
Muazma Ali il 21 Nov 2021
Risposto: Image Analyst il 21 Nov 2021
Hi!
I want to ask whether it is possible to send 'result ' clause as input to a function;
I have this code:
if antall_salter_tilgjengelige==3
S={'NH4Cl'; 'MgCl2'; 'CaCl2'; 'KCl'; 'ZnSO4'; 'NaCl'; 'ZnBr2'; 'CH3CO2K';'HCOOK';' HCOONa'; 'CaBr2'};
str={'Choose the salts available'};
result=listdlg('Promptstring',str, 'ListSize', [100,100], 'ListString', S, 'SelectionMode', 'multiple');
% everything that comes below here ,
% I want that segment to be a part of a function
% instead of having it at the same place as the code written above.
% The question is then whether I can send ''result'' as an input to a function...
if all(ismember(result,[1 2 3 ]))
forste_saltet=result(1,1);
andre_saltet=result(1,2);
tredje_saltet=result(1,3);

Risposte (1)

Image Analyst
Image Analyst il 21 Nov 2021
The answer is yes.
if antall_salter_tilgjengelige==3
S={'NH4Cl'; 'MgCl2'; 'CaCl2'; 'KCl'; 'ZnSO4'; 'NaCl'; 'ZnBr2'; 'CH3CO2K';'HCOOK';' HCOONa'; 'CaBr2'};
str={'Choose the salts available'};
result=listdlg('Promptstring',str, 'ListSize', [100,100], 'ListString', S, 'SelectionMode', 'multiple');
% everything that comes below here ,
% I want that segment to be a part of a function
% instead of having it at the same place as the code written above.
% The question is then whether I can send ''result'' as an input to a function...
otherResults = myFunction(result)
end
%=======================================================================================
function otherResult = myFunction(result)
otherResult 0; % Whatever you want to return...
if all(ismember(result,[1 2 3 ]))
forste_saltet=result(1,1);
andre_saltet=result(1,2);
tredje_saltet=result(1,3);
end

Categorie

Scopri di più su Construct and Work with Object Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by