フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

is it possible to input two variable values while loading a function from commend menu?

1 回表示 (過去 30 日間)
Young Lee
Young Lee 2018 年 11 月 7 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
function [] = w8ass7p4(y)
y = [n m]
%number of files
for i = 1:n
% variable for folder
a = ['binder',num2str(i)]
mkdir(a)
for j= 1:m
matrix = magic(j)
b = ['texfiles',num2str(j)]
c = [a,'\',b]
dlmwrite(c,matrix,'|')
end
end
Im writing a function so that It can loop and create n of folders and m of files
is it possible to load a function while inputting two variable, if so, how can I improve my code?? Thank you!!
  1 件のコメント
Caglar
Caglar 2018 年 11 月 7 日
Your code is illogical. Your input is y but then you are defining y. That would delete the input y. I think you want to do
[n m]=y
Also, you can do
function [] = w8ass7p4(n,m)
so that it accepts 2 input variables.

回答 (2 件)

Stephen23
Stephen23 2018 年 11 月 7 日
編集済み: Stephen23 2018 年 11 月 7 日
You should use sprintf and fullfile:
D = 'directory where the folders should be located';
for ii = 1:n
B = sprintf('binder%d',ii);
mkdir(fullfile(D,B))
for jj = 1:m
matrix = magic(jj);
T = sprintf('file%d.txt',jj);
F = fullfile(D,B,T);
dlmwrite(F,matrix,'|')
end
end

madhan ravi
madhan ravi 2018 年 11 月 7 日
編集済み: madhan ravi 2018 年 11 月 7 日
[n m]=size(y) %change this
dlmwrite(c,matrix,'delimiter ','|') %change this
Put
w8ass7p4(y) %y should be a matrix
In command window

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by