フィルターのクリア

Is it possible to use function for a fullfile or readmatrix data storage?

3 ビュー (過去 30 日間)
Jigar Gopani
Jigar Gopani 2022 年 6 月 22 日
編集済み: Stephen23 2023 年 8 月 31 日
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
Steven Lord 2022 年 6 月 22 日
What does "it did not work out" mean in this context?
  • 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.
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
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
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 ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by