Copy and paste current MATLAB code in another folder

3 ビュー (過去 30 日間)
Jay Vaidya
Jay Vaidya 2021 年 2 月 4 日
コメント済み: Jay Vaidya 2021 年 6 月 6 日
I want to make a copy of my current code in execution and paste it into a folder I specify. But I am not sure how to do that. This should be done while the execution of the code itself. Meaning, it should not be a standalone code that just copies any random file to a directory. I need to copy the current code in execution to be copied to a new directory each time (while execution).
Thanks in advance.

採用された回答

Steven Lord
Steven Lord 2021 年 2 月 4 日
Why are you trying to do this? If you're trying to modify the copy and later run the modified copy, I would instead have the function accept input arguments related to the change and take action based on the specific values with which it is called.
For example, if I wanted to have a function that can display either the sine, cosine, or tangent of a set of data you could have a function that you copy and modify, or you could have a function that accepts the trig function:
subplot(3, 2, 1)
plotTrigFunction(@sind)
subplot(3, 2, 2)
plotTrigFunctionStr('sin')
subplot(3, 2, 3)
plotTrigFunction(@cosd)
subplot(3, 2, 4)
plotTrigFunctionStr('cos')
subplot(3, 2, 5)
plotTrigFunction(@tand)
subplot(3, 2, 6)
plotTrigFunctionStr('tan')
function plotTrigFunction(funToPlot)
x = 0:360;
plot(x, funToPlot(x), 'DisplayName', func2str(funToPlot))
legend show
end
function plotTrigFunctionStr(name)
x = 0:360;
switch name
case 'sin'
y = sind(x);
case 'cos'
y = cosd(x);
case 'tan'
y = tand(x);
otherwise
error("This function, as written, can only process " + ...
"the sine, cosine, and tangent functions");
end
plot(x, y, 'DisplayName', name)
legend show
end
  1 件のコメント
Jay Vaidya
Jay Vaidya 2021 年 6 月 6 日
Hi,
I needed the MATLAB code to be stored in each new folder which is created by the execution of the same MATLAB code. This is for the record that to know what code generates what data in each folder.

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by