Clear Filters
Clear Filters

sending 'result' as an input to a function

1 view (last 30 days)
Muazma Ali
Muazma Ali on 21 Nov 2021
Answered: Image Analyst on 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);

Answers (1)

Image Analyst
Image Analyst on 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

Categories

Find more on Construct and Work with Object Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!