How to plot portion of a vector in matlab?

50 ビュー (過去 30 日間)
MatlabFan
MatlabFan 2013 年 2 月 9 日
コメント済み: Chris 2014 年 12 月 9 日
Hi,
I am trying to plot a portion (from indis to length(vector)) of a vector (vector) in matlab using the following syntax:
plot(-vector(indis:length(vector))+1)
I don't know what indis will be, that's why my only option is to use indis in the plotting syntax. My issue is that matlab plots -vector(1:length(vector))+1 instead of plotting it as I demanded.
Please help me with this issue.
I would really appreciate your help.
Thanks.
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 9 日
What is indis ? What do you want to plot?
MatlabFan
MatlabFan 2013 年 2 月 9 日
indis is an integer, which value I don't know what it will be. I do know that is is an integer greater than 1 and less than length(vector). I am trying to plot 1-vector(indis:length(vector)).

サインインしてコメントする。

採用された回答

Shashank Prasanna
Shashank Prasanna 2013 年 2 月 9 日
The following piece of code must make things clearer: I make few modifications, Notice I plot with respect to 'x'. If you don't then MATLAB will always assume x = 1:length(vector)
% Create Data
x=0:0.1:2*pi;
vector = sin(0:0.1:2*pi);
% Plot everything
indis=1;
plot(x(indis:length(vector)),-vector(indis:length(vector))+1,'r--');
axis([0 6 0 2])
hold on
% Plot from 20 onwards
indis=20;
plot(x(indis:length(vector)),-vector(indis:length(vector))+1);
axis([0 6 0 2])
  2 件のコメント
MatlabFan
MatlabFan 2013 年 2 月 9 日
You guys are awesome. I just realized that I had skipped an important step in my code, causing it to not produce the output I expected.My algorithm was correct, I just missed a step. I guess it is because I did not get enough rest lately. But, I certainly appreciate you all, for being there and providing your help. Thanks.
Chris
Chris 2014 年 12 月 9 日
Thnx! This helped me a lot!

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 9 日
編集済み: Azzi Abdelmalek 2013 年 2 月 9 日
v=1:100
plot(v(40:end))
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 9 日
編集済み: Azzi Abdelmalek 2013 年 2 月 9 日
You don't need length(vector). just write
y=1-vector(indis:end)
plot(y)
but you need to assign a value to indis
MatlabFan
MatlabFan 2013 年 2 月 9 日
You guys are awesome. I just realized that I had skipped an important step in my code, causing it to not produce the output I expected.My algorithm was correct, I just missed a step. I guess it is because I did not get enough rest lately. But, I certainly appreciate you all, for being there and providing your help. Thanks.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by