xlsread and its output argument in a for loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hsinho Huang
el 8 de En. de 2017
I am wondering how to code a for loop to have the respective outputs from reading the 3 Excel files.
[num1,txt1,raw1] = xlsread('D:\exp\data1.xlsx','sheet1','A5:F50');
[num2,txt2,raw2] = xlsread('D:\exp\data2.xlsx','sheet2','A5:F50');
[num3,txt3,raw3] = xlsread('D:\exp\data3.xlsx','sheet3','A5:F50');
I tried the following code but had an error 'Error: An array for multiple LHS assignment cannot contain M_STRING.'
for i=1:3
['num',num2str(i)','txt',num2str(i)','raw',num2str(i)'] = xlsread('D:\exp\data',num2str(i),'.xlsx','sheet',num2str(i)','A5:F50');
end
0 comentarios
Respuesta aceptada
Stephen23
el 8 de En. de 2017
Editada: Stephen23
el 8 de En. de 2017
Don't do this. Read this to know why:
You should simply import the data into cell arrays and use indexing. This will be much faster and more robust:
N = 3;
Cnum = cell(1,N);
Ctxt = cell(1,N);
Craw = cell(1,N);
for k = 1:N
str = ['D:\exp\data',num2str(k),'.xlsx'];
[Cnum{k},Ctxt{k},Craw{k}] = xlsread(str,'sheet',num2str(k)','A5:F50');
end
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!