using the int i as output name

2 visualizaciones (últimos 30 días)
Sobel Captain
Sobel Captain el 19 de Nov. de 2015
Editada: Stephen23 el 19 de Jun. de 2019
Hi,everyone.I would like to ask a question about using the int i as output name , I hope someone could help me . such as for i=1:30; I have a function I would like to put 30 different input using for loop . just like input (i)=xxx ->my program->output (i)=xxxx I would like to have 30 input(some audio files 1.wav 2.wav 3.wav ............) and 30 output , output 1 output 2 output 3......, I have tried output(int i) that's not works , also int2str(i) not working too. could anyone tell me how to do that , thanks a lot .

Respuesta aceptada

Walter Roberson
Walter Roberson el 19 de Nov. de 2015
  6 comentarios
Walter Roberson
Walter Roberson el 19 de Nov. de 2015
Yes, put it in a cell.
Sobel Captain
Sobel Captain el 19 de Nov. de 2015
Editada: Sobel Captain el 19 de Nov. de 2015
oh....another problems now i have 2 for loop now , outer loop i=1:10 inner loop k=1:3 and if my output want to be a cell ( output to cols and rows depends on i and k , such as i=1 k=1 fill in the 1:1 of the cell i=10 , k=3 , fill in the 10:3 ) so that's should be a 3x10 cell. and I tried to use( ans{i,k}=result; ) , the cell become 10x10 and so many blank values , is there anyway to do that , thanks a lot for your help , I am new to matlab .

Iniciar sesión para comentar.

Más respuestas (2)

Thorsten
Thorsten el 19 de Nov. de 2015
This is a possible framework of how to process 30 files:
for i = 1:30
input_filename = sprintf('%d.wav', i)
% read input_fileame, compute output
output_filename = sprintf('output%d', i)
% write output to file
end
  2 comentarios
Sobel Captain
Sobel Captain el 19 de Nov. de 2015
thanks a lot , but my output is not files is some values , I want it to be shown at the workspace(right side of matlab)
output_filename = sprintf('ans%d', i); output_filename=myans;
and I hope there are ans 1 ans 2 ...... ans 30 at the workspace ,myans is the result of the program, but I tried that method , not works
Thorsten
Thorsten el 19 de Nov. de 2015
Editada: Thorsten el 19 de Nov. de 2015
You can create dynamically named variables with eval, but this is not considered good programming practice:
eval(['ans', int2str(i) '= myans;'])
Instead, if myans has a different size for different i, use
ans{i} = myans;
or, if myans has the same size for all i:
ans(i) = myans; % if myans is a single value
or
ans(i,:) = myans; % if myans is a 1xn vector
or
ans(i, :,:) = myans; % if myans is a n x matrix
and so on.

Iniciar sesión para comentar.


Stephen23
Stephen23 el 19 de Nov. de 2015
Editada: Stephen23 el 19 de Jun. de 2019
  2 comentarios
Ilham Hardy
Ilham Hardy el 19 de Nov. de 2015
This is everywhere :D
Stephen23
Stephen23 el 19 de Nov. de 2015
Editada: Stephen23 el 19 de Nov. de 2015
Yep, because beginners keep dreaming it up as The Best Way To Program™.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by