Trouble reading in multiple xls files

clear all; % clears all variables from your workspace
close all; % closes all figure windows
clc; % clears command window
%%define number of trials
njump=81;
[1] input variables of trial data
%%%%%%%%%%%%%%%%%%%%%
%read in excel data in CSV format
for i=1:njump
data1=xlsread('Trial%i.csv','Trial%i','A1:E7000'); % jump data
end
^^^^^ this is what I have written, however it will not read in all of the data that I need. I have 81 trials but it will not read them in even when I have put a loop in. I am quite a novice in matlab and I don't understand what I am doing wrong. Can anyone help?

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 5 月 12 日
編集済み: Azzi Abdelmalek 2014 年 5 月 12 日

0 投票

data1 is overwriten each loop, use
for i=1:njump
data1{i}=xlsread(sprintf('Trial%i.csv',i),sprintf('Trial%i',i),'A1:E7000'); % jump data
end
If you want to clear all workspace variables use
clear
% without all

10 件のコメント

Adrienne
Adrienne 2014 年 5 月 12 日
I have just typed that exact code in, however this does not solve it.
I want to be able to read in all xlsx files from trial08-81
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 5 月 12 日
for i=1:njump
data1{i}=xlsread(sprintf('Trial%i.csv',i),sprintf('Trial%i',i),'A1:E7000'); end
Adrienne
Adrienne 2014 年 5 月 12 日
編集済み: Azzi Abdelmalek 2014 年 5 月 12 日
I have now written this:
for i=1:njump
x=sprintf('Trial%i.csv',i),sprintf('Trial%i',i),'A1:E7000';% jump data
data{i}=xlsread(x);
end
from your help. However it does not want to read the trial numbers which are trial01,trial02 etc. because of the zero?
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 5 月 12 日
What trial01 represent in your file?
Adrienne
Adrienne 2014 年 5 月 12 日
data that i'm trying to import but it says it cannot find it, it is in all the same folders
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 5 月 12 日
for i=1:njump
x=sprintf('Trial%i.csv',i);
data{i}=xlsread(x,'A1:E7000');
end
Adrienne
Adrienne 2014 年 5 月 12 日
thank you for your help it ended up being this:
for i=1:njump; x=sprintf('Trial%02d.csv',i),sprintf('Trial%02d',i),'A1:E7000';% jump data data{i}=xlsread(x,'A1:E7000'); end
BOB
BOB 2014 年 5 月 14 日
Hi,
I've tried to use this same code for my similair problem. However it doesn't seem to bring in any data.
My variables read:
Ans: 'A1:E7000', when you go into it it just says A!:E7000
data: cell, which when you go into just has 81 cells saying 6004x5 double
i: 81, when you go into it just says 81
njump: 81, when you go into it just says 81
x: 'Trial81.csv', when I go into this it just says 'Trial81.csv'
Is this what I am meant to have/is this what you got?
What did you do next?
Thanks
Image Analyst
Image Analyst 2014 年 5 月 14 日
Try using all 3 outputs of xlsread()
[numbersOnly, textOnly, everything] = xlsread(filename);
BOB
BOB 2014 年 5 月 16 日
What shall I put this instead of?
This is the code I am trying currently:
:

サインインしてコメントする。

タグ

質問済み:

2014 年 5 月 12 日

コメント済み:

BOB
2014 年 5 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by