0
votes

I have 100 .xlsx files. Each file has 100*100 (row*column).I used blow code to read them.

clear;
clc;
M= 100;
data = cell(1, M);
  for k = 1:N
  N= sprintf('Data%d.xlsx', k);
  data{k} = importdata(N);
end

I have couples of questions

  • How can I plot each column starting from column number 2 against column number1 for all matrices? I should have 99 plot for each matrix.
  • How can I extract data from the structure to do some operation on it? I should have 100 matrices with size (100*100).

I tried below code to extract data, but it isn't working. it is saving only one matrix

for i=1:100
    z=data{1,i}.data;
end

I tried this code to make 3D matrix

data=zeros(100,100,100)
 M= 100;
for k = 1:M
  N = sprintf('file%d.xlsx', k);
  data(:,:,k)=importdata(N);
end

Thanks

1
Are you indexing things right in the second for cicle? - 16per9
I'd suggest not using cells in the first place if your matrices are all 100*100. You can just define a matrix data=zeros(100,100,100) and in your loop set data(:,:,k)=importdata(N). Then it's just standard plotting over the slices - BillBokeey
@BillBokeey , I used above code to change data to 3D matrix but I still have problem how to extract data from structure - user6052232
Did you put the file data somewhere? It would be easier or faster - 16per9

1 Answers

0
votes

So your question is a little bit confusing, but I think I know what you're after. Is there a reason you didn't use XLSREAD?

for i = 1:100
    [data{i},~,~] = xlsread(sprintf('Data%d.xlsx',i));
end

for i = 1:length(data)
    for j = 2:size(data{i},2)
        figure;
        plot(data{i}(:,1),data{i}(:,j)
    end
end