combining different row vectors of different lengths

조회 수: 1 (최근 30일)
Adil Saeed
Adil Saeed 2022년 8월 15일
댓글: Adil Saeed 2022년 8월 16일
t1 = 30;
t2 = 15;
t3 = 12;
t4 = 2.4;
t5 = 2.1428;
t6 = 2.5;
v1 = 0:t1:900-t1;
v2 = 900:t2:1800-t2;
v3 = 1800:t3:2700-t3;
v4 = 2700:t4:3600-t4;
v5 = 3600:t5:4500-t5;
v6 = 4500:t6:5400-t6;
I am wondering if i can combine all these 'v' vectors into one, whilst keeping the conditions set. So at 900, the values increase by t2 rather than t1 and at 1800 the values increase by t3 rather than t2 etc.

채택된 답변

Image Analyst
Image Analyst 2022년 8월 15일
vout = [v1,v2,v3,v4,v5,v6];
  댓글 수: 4
Adil Saeed
Adil Saeed 2022년 8월 15일
within my loop currently, 's' has remained constant, due to t being constant. However now i would like 't' to change based after a certain number of impacts / positions or the time period, which ive tried using the 'TV' vector. so during 0 - 900 s, impact occurs every 30 s, therefore t would be 30 within this range in my loop, and this would provide 30 positions all a distance of 's'. The next interval is 900 - 1800 s, impact occurs every 15 s therefore t would be 15 within this range in my loop and i would like 's' to change as this would be from 30 - 90 positions and so on until 5400 s or 1320 impact / positions. the iter demonstrates the total number of impacts / positions.
So i need my current loop to be modified to change t, according to what position / iter it is curently at, based on what I've tried using as the 'TV' vector. I've tried my best to explain it, if you think my methodology is completely wrong let me know.
Adil Saeed
Adil Saeed 2022년 8월 16일
I think i found a way to solve it, would you mind just double checking it, the code might make it easier for you to understand what i was trying to do
clc, clear;
x0 = 0; y0 = 0;
Sr = [x0 y0]; %Source coordinates
IL = 160; %Impact Level
v = 2.35; %Speed
T = 5400; %Total Time
iter = 1320; %number of Positions / Impacts / Recordings
TV = [0:30:900-30, 900:15:1800-15, 1800:12:2700-12, 2700:2.4:3600-2.4, 3600:2.1428:4500-2.1428, 4500:2.5:5400-2.5]; %Time vector between each impact
X = zeros(iter,1);
Y = zeros(iter,1);
RL = zeros(iter,1);
% starting condition - random position start
%Z = [randi([-10 10]) randi([-10 10])];
Z = [5 2];
d = sqrt((Z(1)-x0)^2+(Z(2)-y0)^2); % Pythagoras Theorem for distance between the Source and initial Reciever points
for i = 1:iter
if 0<i && i<=30
t = 30;
elseif 30<i && i<=90
t = 15;
elseif 90<i && i<=165
t = 12;
elseif 165<i && i<=540
t = 2.4;
elseif 540<i && i<=960
t = 2.1428;
elseif 960<i && i<=1320
t = 2.5;
end
s = v*t;
SL = 212 + 20*log10(10); %single source value that has been kept constant throughtout
% assign position coordinates
x = Z(1);
y = Z(2);
% save current position
X(i) = x;
Y(i) = y;
%Prpoagation Loss
s1 = sqrt((x-x0)^2+(y-y0)^2); % Pythagoras Theorem for distance between the 2 (Source and Reciever) points
theta = atan2d(y,x);
TL = 20*log10(s1); %Transmission Loss
RL(i) = SL - TL; % Receive Level
%RL(i) = RL(i) + 10.*log10(t); %encorporate the energy exposure at the position for t(s), (assumption)
r = d + (i-1)*s;
if RL(i) > IL
%Update for position based on random biased flee direction
x = Z(1) + s*cosd(theta); % use cosd for angle in degrees
y = Z(2) + s*sind(theta); % use sind for angle in degrees
Z = [x y]; % update current location
else
%Update for position based on random direction
alpha = 360*rand;
x = Z(1) + s*cosd(theta + alpha); % use cosd for angle in degrees
y = Z(2) + s*sind(theta + alpha); % use sind for angle in degrees
Z = [x y]; % update current location
end
% save result
X(i) = x;
Y(i) = y;
end
%RECEIVE LEVEL MODEL
figure
set(plot(TV,RL,'.'),'markersize',3)
hold on;
set(plot(TV,SL,'.'),'markersize',3)
xlabel('Time (s)')
ylabel('Decibels (dB)')
legend({'Individual Strike Recieve Level (dB re μPa^2s)','Individual Strike Source Level (dB re μPa^2s-m)'},'Location','east')

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by