フィルターのクリア

writing the code as a function

1 回表示 (過去 30 日間)
Esra Demirbilek
Esra Demirbilek 2022 年 3 月 21 日
コメント済み: Jan 2022 年 3 月 22 日
Hi everyone,
I have created an algorithm code as below, but I cannot specify it as a function, can you help please?
N = 138;
j=1;
for i = 1:2:N
sira(1,i) = int32(j);
sira(1,i+1) = int32(j);
j = j+1;
end
newM=birincifaz.*(1:size(birincifaz,1))';
newM(:,1)=[];
for k=1:size(newM,2)
r=unique(newM(:,k));
r=r(r~=0);
B(:,k)=r(randi(length(r),20,1));
end
yeni=ikincifaz.*(1:size(ikincifaz,1))';
yeni(:,1)=[];
for e=1:size(yeni,2)
m=unique(yeni(:,e));
m=m(m~=0);
H(:,e)=m(randi(length(m),20,1));
end
out = reshape(vertcat(B,H), 20, []);
D = [sira ; out]
new_idx = randperm(size(D,2)/2)*2-[1; 0];
rassall= D(:,new_idx(:))
Thanks in advance
  2 件のコメント
Torsten
Torsten 2022 年 3 月 21 日
function [the variables you want as output] = f(the variables you need as input)
So think about what the function should calculate as output and what the function needs as input to calculate this output.
Jan
Jan 2022 年 3 月 22 日
@Esra Demirbilek: Please do not delete the contents of the question after answers have been given.

サインインしてコメントする。

採用された回答

Cris LaPierre
Cris LaPierre 2022 年 3 月 21 日
If you move your code to a live script, you can use the Refactor tool to automatically turn the selected code into a function. See here and here.
If you are using R2021b or newer, refactoring is available in the editor as well (.m files)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by