Not sure what commands to use for eg. 0<x<a, when certain values are given
이전 댓글 표시
I'm trying to make a script that when values for Q, a and L are plugged in the following are computed (a random x variable in between the following):
W for 0 < x < a
Qw{
0 for a < x < L
and
-W(a-x) for 0 ≤ x ≤ a
Mw{
0 for a < x ≤ L
I'm not even sure where I would start to be able to do this, so any help would be appreciated. Even just some tips. Thanks for any advice guys!
댓글 수: 3
Image Analyst
2013년 11월 6일
Where does Q come in to play?
dave357
2013년 11월 6일
Image Analyst
2013년 11월 7일
OK, so doesn't my code below do the trick?
답변 (2개)
Kelly Kearney
2013년 11월 6일
You might want to start by reading up on logical indexing (search the documentation). Your first example:
Qw = zeros(size(x));
Qw(x > 0 & x < a) = W;
Image Analyst
2013년 11월 6일
Try something like this:
L = 20
a = 3
W = randi(9, 1, L)
% Define x to have the same number of samples between 0 and L as W does.
x = linspace(0, L, length(W));
% Get two ranges
range1 = x<a
range2 = x > a
% Make arrays
Qw = zeros(1, length(W));
Qw(range1) = W(range1)
Mw = zeros(1, length(W));
Mw(range1) = -fliplr(W(range1))
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!