Function capability in Matlab
Mostrar comentarios más antiguos
Dear all,
I have 30 source data in my matlab folder, data1.dat,data2.dat..data30.dat.. I have the exact code for each one of these source code. I thought to create one function for all then when running it from the command to specify which data source i want to run !! I did
function work ('filename')
mywork = importdata (filename)% before it was data1.dat..
but its not correct, how can I achieve this?
Respuesta aceptada
Más respuestas (2)
Jan
el 15 de Ag. de 2011
function work(filename) % No quotes!
mywork = importdata (filename)
3 comentarios
Paulo Silva
el 15 de Ag. de 2011
the variable mywork should be returned by the function :)
Jan
el 15 de Ag. de 2011
@Paulo: Does "but its not correct, how can I achieve this?" mean, that Susan wants to achieve an incorrect code?
Paulo Silva
el 15 de Ag. de 2011
maybe I don't know lol
Paulo Silva
el 15 de Ag. de 2011
%just in case you discard that function and just want to import all files
for n=1:30
MyWork{n} = importdata(['data' num2str(n) '.dat']); %you might not need the '.dat'
end
3 comentarios
Jan
el 15 de Ag. de 2011
"['data' n '.dat']" is not correct, better: sprintf('data%ddat', n)
Paulo Silva
el 15 de Ag. de 2011
why not? it works just fine in this case, I'm confused :/
Paulo Silva
el 15 de Ag. de 2011
ohhh now I see, I forgot the conversion from double to string, silly me
['data' num2str(n) '.dat']
Categorías
Más información sobre String en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!