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?

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 12 Mai 2014
Bearbeitet: Azzi Abdelmalek am 12 Mai 2014

0 Stimmen

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 Kommentare

Adrienne
Adrienne am 12 Mai 2014
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
for i=1:njump
data1{i}=xlsread(sprintf('Trial%i.csv',i),sprintf('Trial%i',i),'A1:E7000'); end
Adrienne
Adrienne am 12 Mai 2014
Bearbeitet: Azzi Abdelmalek am 12 Mai 2014
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 am 12 Mai 2014
What trial01 represent in your file?
Adrienne
Adrienne am 12 Mai 2014
data that i'm trying to import but it says it cannot find it, it is in all the same folders
for i=1:njump
x=sprintf('Trial%i.csv',i);
data{i}=xlsread(x,'A1:E7000');
end
Adrienne
Adrienne am 12 Mai 2014
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 am 14 Mai 2014
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
Try using all 3 outputs of xlsread()
[numbersOnly, textOnly, everything] = xlsread(filename);
BOB
BOB am 16 Mai 2014
What shall I put this instead of?
This is the code I am trying currently:
:

Melden Sie sich an, um zu kommentieren.

Kategorien

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by