- 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!