Effacer les filtres
Effacer les filtres

xlsread with changing starting point

3 vues (au cours des 30 derniers jours)
Bart
Bart le 11 Sep 2013
Hello all,
I've had some questions before, and everytime I did get an answer, so now I will try it again.
I'm using matlab to get some data out of a Excel document.
At the moment I'm using this code:
dir_struct = dir('*.xlsx');
for i = 1:numel(dir_struct)
number(i) = str2double(dir_struct(i).name(10:(10+numel(dir_struct(i).name)-16))); % get the number-string out of the filename and turn it into a number (I have fixed the format there)
end
[revised_numbers, order] = sort(number);
for i = 1:numel(order)
[num, tekst, raw] = xlsread(dir_struct(order(i)).name,'MISC','B9:C16');
I've received this code in a question earlier. I wanted to use xlsread, but the excel file changes in name over time, so the part where the excel file is mentioned, is now numerical.
This code works fine for me.
My next problem has this code involved.
In the worksheet MISC, the matrix defined is now B9:C16. B9 is i=1, B10 is i=2 etc.
Now, the start of i=1 changes. At the moment, B9 is i=1. But in the future, B12 or B13 for example can be i=1.
What I want is the following code, if possible ofcourse.
Above the data that I want, there is always the text: "Simulation input".
Is it possible for matlab, to 'search' the column B for this text, and set that cell to i=1? So that the place of the start can be everywhere in column B.
I hope that this is clear for you to understand. If not, I will change it and I will try to make it more sence.
I would like to thank you in advance!
Greets, Bart

Réponses (2)

Image Analyst
Image Analyst le 11 Sep 2013
You can use ismember() to search your column for particular text string. It will give you the row(s) where it was found. Then set them to 1.
  9 commentaires
Image Analyst
Image Analyst le 25 Sep 2013
Attaching your workbook to your message would make it easier if someone wants to try something. I can't get to it for several hours, if at all.
Bart
Bart le 25 Sep 2013
Excuse me, here are my two files.
In excel, the data that I need are under Simulation input. I can only upload .xls, so i've changed that in my m-file also. I hope that it still works.
Thanks again. Greets, Bart

Connectez-vous pour commenter.


Bart
Bart le 18 Sep 2013
Hello,
Excuse me for my late answer!! I will try to use your answer, thank you for that.
If I understand it correctly, I can put the code:
ismember(Simulation input)= 1
in front of my start with i=1 etc? (I'm not that good with matlab, so maybe I need a little more help with this than intended...)
Thank you in advance!
Bart

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by