Run function multiple times

11 ビュー (過去 30 日間)
Joel
Joel 2023 年 4 月 13 日
編集済み: Sachin Lodhi 2024 年 6 月 12 日
Hi
I have the following function and input
Abonnemang=24200;
filename="Data.xlsx"
[max_val,t0_pos1,peak_width]=FLEXfun(Abonnemang,filename);
The output variables have these formats:
Now I want the function to run two times, so that the output variables have the size 9x2. I tried this but of course it did not work, but maybe you see my point. The function is also generating graphs. They become misformed when I try to run the function 2 times, even without a loop.
Abonnemang=[24200 20000];
filename=["Data.xlsx" "skottar.xlsx"];
for i=1:2
[max_val(:,i),t0_pos1(:,i),peak_width(:,i)]=FLEXfun(Abonnemang(i),filename(i));
end

回答 (1 件)

Sachin Lodhi
Sachin Lodhi 2024 年 6 月 12 日
編集済み: Sachin Lodhi 2024 年 6 月 12 日
Hello Joel,
To achieve the desired output where each of the variables 'max_val', 't0_pos1', and 'peak_width' have the size '9x2' after running the 'FLEXfun' function twice with different inputs, and to manage the graph generation issue, first pre-allocate the output variables, where each variable has size '9x2' and then assign values to these variables, as shown in the code snippet below:
% Pre-allocate matrices
numOutputs = 9;
max_val = zeros(numOutputs, 2);
t0_pos1 = zeros(numOutputs, 2);
peak_width = zeros(numOutputs, 2);
% Run loop
for i = 1:2
[max_val(:,i), t0_pos1(:,i), peak_width(:,i)] = FLEXfun(Abonnemang(i), filename(i));
end
Note: Ensure that the outputs from FLEXfun are correctly sized (9 elements long). If FLEXfun inherently does not return outputs of this size, you might need to adjust FLEXfun or handle the outputs accordingly.
I hope this helps!

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by