Error: Unbalanced or unexpected parenthesis or bracket

The matlab show this error "Error: Unbalanced or unexpected parenthesis or bracket." in this part of the code:
%**************************************
nome = '105.txt';
[pathstr, name, ext] = fileparts(nome);
load(nome);
x=eval([name '(:,1)']);
y=eval([name '(:,2)']);
z=eval([name '(:,3)']);
%*************************************
---------------------------------------------------------------
105.txt contains 3 columns with several rows...
But on my friend's pc don't show this error... I have a Asus x64, with windows 10 and Matlab R2014b...
I think the problem is not from the code as it was functional on other pc's. I think it has to do with my compiler, but I don't know how to fix it ...
Already installed the version Matlab 6.5 R13, but the same error appears ...
What may be the source of this error?

6 comentarios

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH el 11 de Nov. de 2019
Editada: JESUS DAVID ARIZA ROYETH el 11 de Nov. de 2019
name is a variable or is the file name.txt?
¿Name es una variable o un archivo de texto llamado "name.txt"?, ya que para que no te dé error ahí name debe ser un string
Ricardo Henriques
Ricardo Henriques el 11 de Nov. de 2019
Editada: Walter Roberson el 13 de Nov. de 2019
The "name" came from of "[pathstr, name, ext] = fileparts(nome);"
The previous code is:
%********************************************
nome = '105.txt';
[pathstr, name, ext] = fileparts(nome);
load(nome);
x=eval([name '(:,1)']);
y=eval([name '(:,2)']);
z=eval([name '(:,3)']);
%**********************************************
*
105.txt contains 3 columns with several rows...
Adam
Adam el 11 de Nov. de 2019
Editada: Adam el 11 de Nov. de 2019
The 2nd output of fileparts is simply a filename. Trying to index into it in that way would be expected to produce an error.
Why not just open the file and read its content in instead of confusing the issue with eval, whose usage is regularly recommended against, for reasons exactly like this?
Stephen23
Stephen23 el 13 de Nov. de 2019
"I think the problem is not from the code ..."
In fact the problem is very badly designed code that relies on complex eval to generate invalid variable names. That code should be thrown away, it is never going to be reliable or efficient.
So how should I replace the code?
Any suggestion?
Steven Lord showed you.

Iniciar sesión para comentar.

 Respuesta aceptada

madhan ravi
madhan ravi el 11 de Nov. de 2019
I think name is variable, it's simply (there is no need for eval):
x = name(:,1);
y = name(:,2);
z = name(:,3);

1 comentario

The "name" came from of "[pathstr, name, ext] = fileparts(nome);"
The previous code is:
%********************************************
nome = '105.txt';
[pathstr, name, ext] = fileparts(nome);
load(nome);
x=eval([name '(:,1)']);
y=eval([name '(:,2)']);
z=eval([name '(:,3)']);
%***********************************************
105.txt contains 3 columns with several rows...

Iniciar sesión para comentar.

Más respuestas (1)

Categorías

Más información sobre Scripts en Centro de ayuda y File Exchange.

Preguntada:

el 11 de Nov. de 2019

Comentada:

el 13 de Nov. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by