File naming based on user input

2 ビュー (過去 30 日間)
Erik Anderson
Erik Anderson 2017 年 3 月 29 日
編集済み: Stephen23 2017 年 3 月 29 日
So, I've got some code begins :
function [ Output ] = flatlandprojection(y)
and ends with
put=transpose(Output)
xlswrite('fileout',put);
end
with some coding mcjiggery in between that produces "Output".. I wondered if there was a way to allow for user input in the function that would determine the name of the created file...
I'm imagining something like... function[Output] = flatlandprojection(y,"desired name") such that this results in .. xlswrite("desired name",put);
as things stand, I have to change the file name by changing the code for the function itself, which feels crumby.
Thank you in advance. I really appreciate all the help I've received from members here.

採用された回答

Walter Roberson
Walter Roberson 2017 年 3 月 29 日
function [ Output ] = flatlandprojection(y, filename)
...
xlswrite(filename, put);
  2 件のコメント
Erik Anderson
Erik Anderson 2017 年 3 月 29 日
I tried that, as it's quite similar to what I imagined. Unless I'm doing something wrong without realizing, I find that that does not work: "Undefined function or variable 'filename'."
It seems like I need to get the function recognize the input as pure text, so that it doesn't try to interpret it. I'm not clear on the syntax required to make this work.
Stephen23
Stephen23 2017 年 3 月 29 日
編集済み: Stephen23 2017 年 3 月 29 日
"I'm not clear on the syntax required to make this work."
The syntax is exactly what Walter Roberson showed you. It will work when you supply the name string as the second input argument to the function when the function is called:
y = ...
name = 'MyFile.txt';
z = flatlandprojection(y, name)
Basic MATLAB useage, such as how to call functions, is covered in the introductory tutorials:

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by