Effacer les filtres
Effacer les filtres

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

4 vues (au cours des 30 derniers jours)
Xel Ch
Xel Ch le 21 Juil 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!

Réponse acceptée

Steven Lord
Steven Lord le 21 Juil 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.

Plus de réponses (0)

Catégories

En savoir plus sur Variables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by