Problem with concatenation, help me

Hello people, I have a problem: I'm trying to cocatenate the following
arquivo = [arquivo int2str(x) '.FIL']
But when i see the content from "arquivo", we have "CUNOV000.FIL1.FIL" I dont want this ".FIL1", only the ".FILL". after "CUNOV000"

8 comentarios

Paolo
Paolo el 22 de Mayo de 2018
Could you please post a snippet of code?
Daniel Fonsêca
Daniel Fonsêca el 22 de Mayo de 2018
Editada: Geoff Hayes el 22 de Mayo de 2018
When I write
arquivo = [arquivo int2str(x) ',' 'FIL']
It's showed
arquivo = CUNOV000,FIL
but when I type
arquivo = [arquivo int2str(x) '.' 'FIL']
It showed the same o problem.
Walter Roberson
Walter Roberson el 22 de Mayo de 2018
If you do not want the .FIL1 then why do you have the int2str() as apart of what you are adding on?
John BG
John BG el 22 de Mayo de 2018
Hi Daniel
I bet the contents of arquivo already contains the file extension, so you may not be removing the file extension before plugging all strings together.
Daniel Fonsêca
Daniel Fonsêca el 22 de Mayo de 2018
When a delete '.FIL' arquivo = CUNOV000 I tried arquivo = [arquivo int2str(x) '.txt'], and arquivo was equal CUNOV000.txt
Daniel Fonsêca
Daniel Fonsêca el 22 de Mayo de 2018
Editada: Walter Roberson el 22 de Mayo de 2018
the code as Paolo asked
for x = 0:qarq
arquivo = [arquivo int2str(x) 'FIL']
[c, msg] = fopen(arquivo);
if c < 0
error('Could not open file "%s" because: "%s"', arquivo, msg);
end
da{1,x}= fread(c)
da{1,x}
fclose(c);
end
Daniel Fonsêca
Daniel Fonsêca el 22 de Mayo de 2018
I have 6 files which I want read and put the datas into cell array called da.

Iniciar sesión para comentar.

Respuestas (1)

Stephen23
Stephen23 el 23 de Mayo de 2018
Editada: Stephen23 el 23 de Mayo de 2018
[~,arquivo] = fileparts(arquivo);
arquivo = sprintf('%s%d.FIL',arquivo,x)
But there is no point in calling fileparts repeatedly in a loop:
[~,fnm] = fileparts(arquivo);
for k = 0:qarq
tmp = sprintf('%s%d.FIL',fnm,k);
[fid,msg] = fopen(tmp,'rt');
assert(fid>=3,msg)
...
fclose(fid);
end

Categorías

Más información sobre Scope Variables and Generate Names en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 22 de Mayo de 2018

Editada:

el 23 de Mayo de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by