combining (concat) matrix in loop to get desired output plot

Hi,
I have two plots gotten from (general_load and special_load), they are time vs force. I want to create a loop where I can concat/merge the special load multiple times into the general load where N is the first position on the general_load and i is the number of times (the distance between the special loads must be N) .
Here is where it gets tricky since I want to keep the plots intact the time must be adjusted according ( eg, when the 1st special_load is added at t=50sec to the general load the entire time column in the matrix must be added by 50 such that there is a seamless connection.
A=xlsread('general_load.xlsx');
B=xlsread('test_gust_special_load');
a_length = A(end,1);
b_length = B(end,1);
N = 10;
%% for one special load in the general i used this approach
C1 = A(A(:,1)<=N,:);
C2 =[B(:,1)+N,B(:,2)];
C3 =A(A(:,1)>N,:);
C4=[C3(:,1)+b_length,C3(:,2)];
CT = vertcat(C1,C2);
%% but I am unable to get the for loop
for i= C4(1,1)+N:N:a_length
P1 =C4(C4(:,1)<=i,:);
P2 =[B(:,1)+i,B(:,2)];
PT = vertcat(P1,P2);
c_length=PT(end,1);
C4=PT(PT(:,1)+c_length,PT(:,2));
end
Z = vertcat(CT,C4);
plot(Z(:,1),Z(:,2));

답변 (1개)

Bob Thompson
Bob Thompson 2019년 2월 20일
편집: Bob Thompson 2019년 2월 20일

0 개 추천

I suspect the issue you're having is because you're using the same C4 without attaching it to Z each time in the loop. This means that instead of attaching each segment of your special and general you only get a final segment. If this is incorrect, then please feel free to expand what you mean by 'I'm unable to get the for loop'.
Glancing over your work I would suggest these changes.
A=xlsread('general_load.xlsx');
B=xlsread('test_gust_special_load');
a_length = A(end,1);
b_length = B(end,1);
N = 10:10:a_length; % I think it's worth it to just start here.
% You don't need to do the first round outside the loop.
mark(1) = 0; % Keep track of where we are in the A matrix
mark(2) = 0; % Keep track of new time values
C = []; % Initialize your end matrix
for i = 1:length(N)
A_seg = A( A(:,1) > mark(1) & A(:,1) <= N(i) , :);
mark(1) = A_seg(end,1);
A_seg(:,1) = A_seg(:,1) + mark(2);
B_seg = B;
B_seg(:,1) = B_seg(:,1) + A_seg(end,1);
C = [C;A_seg;B_seg];
mark(2) = B(end,1)*i; % EDIT**
end

댓글 수: 5

liju Abraham
liju Abraham 2019년 2월 20일
편집: Stephen23 2019년 3월 19일
Hi,
thanks for the reply, it seems from the loop the distance from the special loads keep increasing.
Yes, the internals between the special loads( where the general loads are located) should not increase with the loop.
please see attachement
it seems from the loop the distance from the special loads keep increasing
What exactly do you mean by that? The intervals between the injected special loads should not be increasing, but the total time should be.
Found it. Change the recalculation of mark(2)
mark(2) = B(end,1);
Original answer has been editted to reflect this correction.
Made another edit to the same line, see the original answer.
Hi bob,
Sorry for the late reply. But I think the error still persists even with the edit
*The distance between the special loads are still not equal, especially with smaller interval times
Thanks you for your support

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2017b

질문:

2019년 2월 20일

편집:

2019년 3월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by