How to write a range of numbers in MATLAB?

조회 수: 78 (최근 30일)
Abdul Rahim Mahayadin
Abdul Rahim Mahayadin 2018년 4월 9일
댓글: Walter Roberson 2021년 7월 27일
Hi, I am trying to generate a speed range in MATLAB. Let V is the speed, then how to write the coding to find the speed range of:
0<V<=12
12<V<=20
20<V<=30
30<V<=40
40<V<=50
50<V<=60
60<V<=70
70<V<=80
80<V<=90
90<V<=100
100<V<=110
V>110
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 4월 9일
편집: KALYAN ACHARJYA 2018년 4월 9일
Is this complete question?
Walter Roberson
Walter Roberson 2018년 4월 18일
Please do not close Questions that have been Answered.

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

답변 (4개)

Walter Roberson
Walter Roberson 2018년 4월 9일
or you can use the second output of histc() or the third output of histcounts()

njj1
njj1 2018년 4월 18일
ranges = [0,12,20:10:110]; %end points of requested speeds
for i = 1:numel(ranges)-1
   v{i} = V((V>ranges(i) & (V<=ranges(i+1))); %speeds between endpoints
   numV{i} = numel(v{i}); %number of speed entries between endpoints
end
v{end+1} = V(V>110);

Walter Roberson
Walter Roberson 2021년 7월 22일
편집: Walter Roberson 2021년 7월 22일
theta = (0:60).';
and remember to use cosd() and sind()
Notice the .' there: it is transposing the 0:60 from a row vector into a column vector. When you combine this with row vectors, then the result would be to implicitly expand to two dimensions. For example,
v = 1:100;
theta = (0:60).';
dist = (v - v.^2/100) .* sind(theta);
surf(v, theta, dist, 'edgecolor', 'none')
size(v), size(theta), size(dist)
ans = 1×2
1 100
ans = 1×2
61 1
ans = 1×2
61 100
  댓글 수: 2
rahim njie
rahim njie 2021년 7월 26일
thanks but this didnt work for what im trying to do. i would like to calculate something at every angle between 0-60 degrees. this is my code so far if it helps:
theta= (1:60).'; % precession angle
w_s = 10; % angular velocity of spin
a_s = 6; % angualar acceleration of spin
w_n = 3; % angular velocity of nutation
a_n = 2; % augalar acceleration of nutation
w_p = 5; % angular velocity of precession
a_p = 4; % angular acceleration of precession
%% Geometry values
rA = [0 7.4103 7.1651];
%% vectors
vw_s = [0 w_s*sind(theta) w_s*cosd(theta)]; % spin vector
vw_p = [0 0 w_p]; % precession vector
vw_n = [-w_n 0 0]; % nutation vector
%% Angualar velocity
wi = [-w_n 0 0]; % i component of W
wj = [0 w_s*sind(theta) 0]; % j component W
wk = [ 0 0 (w_p + w_s*cosd(theta))]; % k component of W
W = wi + wj + wk; % Angular Velocity;
Walter Roberson
Walter Roberson 2021년 7월 27일
theta= (1:60).'; % precession angle
w_s = 10; % angular velocity of spin
a_s = 6; % angualar acceleration of spin
w_n = 3; % angular velocity of nutation
a_n = 2; % augalar acceleration of nutation
w_p = 5; % angular velocity of precession
a_p = 4; % angular acceleration of precession
%% Geometry values
rA = [0 7.4103 7.1651];
%% vectors
Z = zeros(size(theta));
vw_s = [Z, w_s*sind(theta), w_s*cosd(theta)]; % spin vector
vw_p = [0 0 w_p]; % precession vector
vw_n = [-w_n 0 0]; % nutation vector
%% Angualar velocity
wi = [-w_n 0 0]; % i component of W
wj = [Z w_s*sind(theta) Z]; % j component W
wk = [ Z Z (w_p + w_s*cosd(theta))]; % k component of W
W = wi + wj + wk; % Angular Velocity;
size(W)
ans = 1×2
60 3

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


KSSV
KSSV 2018년 4월 9일
V = 1:100 ;
idx = V>=10 & V<=20 ; % Get indices of velocities lying between 10 to 20
V(idx)
  댓글 수: 3
KSSV
KSSV 2021년 7월 22일
Yes...you can test it yourself.
v = 1:100
v = 1×100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
rahim njie
rahim njie 2021년 7월 22일
thank.
Also i have written code that solves 3D kinematics problem. the code calculates angular velocity at set precsion angle of 60. what function do i use that will allow me to use the same code but calculate the velocity and angle from 1-60 degrees.
i have vectors in some of the calucations so using 'theta= 1:60' Caused erros
thanks

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by