From User Input to File Name
30 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I am a bit stuck with my script. What I am trying to achieve is to request an input from the user (a number). Then make this input part of the file name that I am trying to export.
This is the code I have written so far, but unfortunately, it does not work.
Where am i going wrong?
clc
clear all
close all
A=2000
prompt = {'Project Number:'};
dlgtitle = 'Input';
dims = [1 50];
definput = {' '};
answer = inputdlg(prompt,dlgtitle,dims,definput)
writematrix(A,'num2str(answer)+TEST.csv')
Many thanks
1 件のコメント
KSSV
2022 年 10 月 17 日
writematrix(A,'num2str(answer)+TEST.csv')
What you are expecting to do from the above line?
採用された回答
Steven Lord
2022 年 10 月 18 日
With the clarification in your comment on the answer from @Enrico Gambini, I would use string operations along with the fullfile function.
n = 4000;
filename = n + "_TEST.csv"
pathname = fullfile("c:\temp", filename)
Note that because the code execution functionality for MATLAB Answers runs on Linux, fullfile used / as the file separator. If you ran that on Windows it would use \. See the filesep function.
computer
And of course you could combine the two lines together to avoid creating the temporary variable filename, if you don't need that separately.
pathname2 = fullfile("c:\temp", n + "_TEST.csv")
その他の回答 (1 件)
Enrico Gambini
2022 年 10 月 17 日
Try to use the function "strcat" and "string"
str=string(answer);
writematrix(A,strcat(str,'+TEST.csv'))
参考
カテゴリ
Help Center および File Exchange で Software Development Tools についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!