How to concatenate strings in Matlab with special characters?

11 visualizaciones (últimos 30 días)
Lizhi
Lizhi el 8 de Abr. de 2014
Respondida: Walter Roberson el 8 de Abr. de 2014
Hello,
just want to do the following things:
prompt = 'Please give the path of the import file: ';
str = input(prompt, 's');
% the user will give a path like C:\..\file.txt %
%str = C:\..\file.txt%
fid = fopen(str); %here error, because fopen needs an argument in ''%
%in stead of fopen(C:\..\file.txt), fopen('C:\..\file.txt')%
I wanted to concatenate the str with other character "'". How shall I do this?
Thanks
Lizhi
  1 comentario
Chandrasekhar
Chandrasekhar el 8 de Abr. de 2014
Editada: Chandrasekhar el 8 de Abr. de 2014
There is no error found here. May be the path of the file entered is wrong. instead of 'input' you can use 'uigetfile' to locate the file.

Iniciar sesión para comentar.

Respuestas (3)

Joseph Cheng
Joseph Cheng el 8 de Abr. de 2014
I agree with Akshata it doesn't look like there should be an issue. The input should already be a string such that fopen should accept it. May I suggest that instead of using input() for a file path, use [file folder]=uigetfile() which will open the windows open file window.

Andreas Goser
Andreas Goser el 8 de Abr. de 2014
Editada: Andreas Goser el 8 de Abr. de 2014
The string concatenation should not be a problem:
a='ä'
b='ö'
[a b]
However maybe the commands before?

Walter Roberson
Walter Roberson el 8 de Abr. de 2014
fopen() does not need to be passed a literal: passing a string value is fine.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by