Splitting up arrays in for loops

5 visualizaciones (últimos 30 días)
Ellen
Ellen el 27 de Mayo de 2020
Respondida: Nadya Owusu el 10 de Nov. de 2022
Hi!
I am using arrays that I would like to split up based on the values in the THIRD column. For example this array:
117 299 126
130 305 126
134 299 127
131 293 127
134 299 128
129 295 128
115 296 132
121 298 132
I would like to split is up at the place where the difference between the third column values is higher than 1 (between the current value and the value underneath it). In this case I would like to end up with the following two arrays:
117 299 126
130 305 126
134 299 127
131 293 127
134 299 128
129 295 128
and
115 296 132
121 298 132
I would also like to apply this to a large dataset so not doing it manually.
I thought about using if else statements in a for loop but I don't know how to how to calculate the difference between the third column values.
Can someone help me in how to start with this?
Thank you!

Respuesta aceptada

David Hill
David Hill el 27 de Mayo de 2020
n=[0,find(diff(M(:,3))>1),size(M,1)];
for k=1:length(n)-1
m{k}=M(n(k)+1:n(k+1),:);
end

Más respuestas (1)

Nadya Owusu
Nadya Owusu el 10 de Nov. de 2022
disp("Question 1:")%Displays question number.
a = 210;%The upper limit of the integral.
b = 0;%Lower limit of the integral.
n = 14;%Number of trapezoid sub-intervals in other words number of sections used.
h = (b-a)/n;%Length of trapezoid.
t = b:n:a;
f = (-3.19892*10.^-8)*(t.^7)+(2.77042*10.^-5)*(t.^6)+(-0.00928)*(t.^5)+(1.49974)*(t.^4)+(-1.18729*10.^2)*(t.^3)+(4.25940*10.^3)*(t.^2)+(-5.42886*10.^4)*(t)+(3.50829*10.^6);%Flow rate(t) equation.
integral = 0;
I want to split up the data from the for loop and add it to an array. please help
for t = b:n:a
At least one END is missing. The statement beginning here does not have a matching end.

Error in connector.internal.fevalMatlab

Error in connector.internal.fevalJSON
array = split(f);
disp(array)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by