フィルターのクリア

How do I change M-STRING to a different string?

4 ビュー (過去 30 日間)
Xel Ch
Xel Ch 2017 年 7 月 21 日
回答済み: Steven Lord 2017 年 7 月 21 日
I am running the following statement within a function, in an attempt to read a Sac file.
if nargin == 0
['filename','pathname'] = uigetfile('*.SAC;*.sac','Select a SAC file');
f = ['pathname','filename'];
if 'filename' == 0
error('Please select a SAC file or use function arguments.');
end
end
When run, an error appears for the second line, which says, "An array for multiple LHS assignment cannot contain M_STRING." I believe this is because of my filename ('/2017152000000004_T4120_1_1.sac/') and pathname ('C:/Desktop/2017152000000004_T4120_1_1.sac./').
I have tried establishing a variable to represent these strings and putting this variable in place of the filename and pathname, but the sac error appears. Is there a way to enter my file and path names as anything besides an M-STRING, or circumvent this issue altogether?
Very little MatLab experience so all answers are appreciated!

採用された回答

Steven Lord
Steven Lord 2017 年 7 月 21 日
You wrote:
['filename','pathname'] = uigetfile('*.SAC;*.sac','Select a SAC file');
You can't specify a char vector as the output of a function call. Specify a variable instead to store that output in that variable.
[filename,pathname] = uigetfile('*.SAC;*.sac','Select a SAC file');
Now use those variables, not the char vectors containing the names of those variables, later in your code.
if filename == 0
% handle the case where the user cancels the uigetfile dialog
end
You may also be interested in using the fullfile function later in your code to combine the filename and pathname variables.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by