- Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
- Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
- Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support so we can investigate.
Is it possible to use function for a fullfile or readmatrix data storage?
조회 수: 3 (최근 30일)
이전 댓글 표시
I am trying to make a function in which I can access the particular path of the folder and from there, I want to use readmatrix to read the .txt file. I tried but it did not work out. Is it possible or does it make any sense to use? Or the functions can only be used for mathematical operations in Matlab.
Looking forward your response asap.
댓글 수: 1
Steven Lord
2022년 6월 22일
What does "it did not work out" mean in this context?
If you show the code as well we may be able to offer suggestions about why it didn't work as you expected and how to correct it.
답변 (1개)
Shuba Nandini
2023년 8월 31일
Hello,
I understand you want to create a function from where text file can be accessed using “readmatrix” function.
Using “ uigetdir” function, you can select the folder from which you want to retrieve the ‘.txt’ file. “uigetdir” opens a modal dialog box that displays the folders in the current working directory and returns the path that you select from the dialog box.
Please refer to the below example on how to get the ‘.txt’ file from the specified folder:
function readtextfile() % This function reads a .txt file using readmatrix
dname = uigetdir('C:\'); % select a folder
data = readmatrix('textfile.m') %select a .txt file
end
Please refer to the following documentation to know more about “uigetdir” and “readmatrix” functions:
I hope this helps you to retrieve the .txt file!
Regards,
Shuba Nandini
댓글 수: 1
Stephen23
2023년 8월 31일
편집: Stephen23
2023년 8월 31일
It is insufficient to call UIGETDIR to return DNAME... which is then completely unused. In order for that code to work correctly, it requires READMATRIX to also have the path to the file.
The best approach is to use FULLFILE:
D = uigetdir('C:\');
F = fullfile(D,'textfile.m');
M = readmatrix(F);
The author also wrapped the code in a function but did not return any output argument, which is unlikely to be useful.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!