필터 지우기
필터 지우기

How can I use an answer from a prompt as a file name?

조회 수: 6 (최근 30일)
Nathan Costin
Nathan Costin 2016년 7월 4일
댓글: Nathan Costin 2016년 7월 5일
I am currently trying to use an answer from a prompt given as a file name for a table that gives the location of cells on an image. However I keep getting error messages or am only able to save the table as one name. Below is the codes that I am using:
prompt1 = 'What would you like the data file to be called?';
filename = input(prompt1,'s');
writetable(centroiddata, filename)
I have tried several solutions to resolving this, including changing the filename in the 3rd line to 'filename' and specifying the file path.
If anyone can help me out I would be very grateful!
Thanks in advance!

채택된 답변

Stephen23
Stephen23 2016년 7월 4일
Try this:
[~,name] = fileparts(input(prompt1,'s'));
writetable(centroiddata, [name,'.txt'])
  댓글 수: 11
Stephen23
Stephen23 2016년 7월 5일
@Nathan Costin: image handling is quite a different topic, and you would be better off asking it a new question.
Nathan Costin
Nathan Costin 2016년 7월 5일
Ok I shall do thank you for your help

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2016년 7월 4일
Why not simply use the function meant for asking the user for a filename?
Why are you not using uiputfile()???
  댓글 수: 3
Image Analyst
Image Analyst 2016년 7월 4일
Try this:
% Get the name of the file that the user wants to save.
% Note, if you're saving an image you can use imsave() instead of uiputfile().
startingFolder = userpath % Or "pwd" or wherever you want.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
Nathan Costin
Nathan Costin 2016년 7월 5일
Thank you, I will give it a shot :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by