hi. i want to shift my sequence to left but there is a problem.
clc;
clear all;
close all;
% our domain in 11
n = 0:10;
x = cos (n*pi/12);
% shift x to left 2 unit
x2 = [x 0 0];
y = 2*x;
y2 = 2*x2;
d = y - y(-2:11-2);
% do should be = 0
stem (n,y2)
the problem is i can't enter a negative value to y(-2:9);
how can i change that line?
-------------------------------------------------------
errore:
Array indices must be positive integers or logical values.
Error in Untitled (line 14)
d = y - y(-2:11-2);

댓글 수: 1

David Hill
David Hill 2020년 10월 21일
I have no idea what you want to do. Please provide and example. [1 2 3 4] goes to what?

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

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 10월 21일
편집: Ameer Hamza 2020년 10월 21일

1 개 추천

n = 0:10;
x = cos (n*pi/12);
y = circshift(x, 2)

댓글 수: 3

Stephen23
Stephen23 2020년 10월 21일
HADIMARGO's "Answer" moved here:
thank you Mr. Ameer. But i don't want to use this function.
i want to shift with this structure :
x2 = [ x 0 0];
HADIMARGO
HADIMARGO 2020년 10월 21일
also this is not my main problem.
my main problem is how to use y(-2:11-2); with that error.
Negative indexes are not supported in MATLAB like they do in python. MATLAB supports something like the following if that helps
n = 0:10;
x = cos (n*pi/12);
y = x([end-1:end 1:end-2])

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2020년 10월 21일

댓글:

2020년 10월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by