Extracting data from a 'for' loop
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Yoham Parelkar
le 17 Déc 2018
Réponse apportée : Yoham Parelkar
le 18 Déc 2018
I have the following input file 'Test_14-Dec-2018.xls' attached
This is my code:
clc;
clear;
dataset = xlsread('Test_14-Dec-2018');
A = dataset(:,1:8);
B = A(A(:,1)==10,:); %for a=10s
k=1;
C=cell(1,4);
for p = 1:4
j=p*9;
i=j-8;
C{k} = B(i:j,:);
d=cell2mat(C);
x = d(:,2);
k=k+1;
end
Basically what the code does is extract that data into the matlab workspace and selects the data only when the first column has '10' data.
In the for loop, every 9 rows are selected and assigned a cell so that I have 9x8 in each 4 cells.
Cell2mat converts those cells into one matrix of 9x32. I am able to extract the second column from that.
Now, I want the data from every 8th column i.e. d(:,8), d(:,16), d(:,24), d(:,32) in a for loop but I am unable to do that.
After that I should be able to plot 'x' with each of those data from each column.
Any kind of help will be appreciated.
10 commentaires
Bob Thompson
le 18 Déc 2018
You need to set 'hold on'. That will allow you to plot multiple lines on the same figure. You can do this before the loop.
Réponse acceptée
Plus de réponses (1)
madhan ravi
le 17 Déc 2018
Modifié(e) : madhan ravi
le 17 Déc 2018
Replying to your latter comment :
y=cell(1,numel(1:8:32));
for l=1:8:32
y{l}=d(:,l);
end
celldisp(y) % [y{:}] to convert it to double from cell
y=d(:,[1:8:32])
3 commentaires
madhan ravi
le 17 Déc 2018
Anytime :) , if my code worked make sure to accept the answer else let know what needs to be done after you analyse(take your time) let me take a short nap by then ;-).
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements 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!