필터 지우기
필터 지우기

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 CenterFile Exchange에서 Variables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by