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

1 visualización (últimos 30 días)
Xel Ch
Xel Ch el 21 de Jul. de 2017
Respondida: Steven Lord el 21 de Jul. de 2017
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!

Respuesta aceptada

Steven Lord
Steven Lord el 21 de Jul. de 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.

Más respuestas (0)

Categorías

Más información sobre Performance and Memory en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by