How do I change M-STRING to a different string?
1 view (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Steven Lord
on 21 Jul 2017
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 Comments
More Answers (0)
See Also
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!