Problem Expanding a Matrix

Hi all,
How can I do the following:
Say that I start with a vector with the elements [5 3 4 9 10] - think of these numbers like daily stock prices. I want to transform this vector into (an approx.) of intraday stock prices - 1/10 of day.
Therefore my vector should look like [ 5 4.8 4.6 4.4 .4.2 4 3.8 3.6 3.4 3.2 3 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9 10]
THank you!!

 채택된 답변

Charles Martineau
Charles Martineau 2012년 5월 31일

1 개 추천

I figured out some other way
x = 0:4; y = [5 3 4 9 10]; >> xnew = 0:.1:4; ynew = interp1(x,y,xnew,'linear');

추가 답변 (3개)

Walter Roberson
Walter Roberson 2012년 5월 31일

2 개 추천

NewV = interp1(1:length(V), V, V(1):.1:V(end));

댓글 수: 1

Charles Martineau
Charles Martineau 2012년 5월 31일
Hi Walter,
Thanks for the help but why I am generating a vector of NaN NaN NaN NaN NaN....
I simply created a vector V (3X1) and I get this strange result.
Thanks!

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

Ryan
Ryan 2012년 5월 31일

1 개 추천

clear i j
elements = [5 3 4]; % Currently what you have
% Matrix containing intraday prices where each row corresponds to the intraday prices for each of the members of elements
intraday = [1 2 3 4 5 6 7 8;1 2 3 4 5 6 7 8;1 2 3 4 5 6 7 8];
j = length(elements);
for i = 1:j
newelements(i,:) = [elements(i),intraday(i,:)];
end

댓글 수: 3

Charles Martineau
Charles Martineau 2012년 5월 31일
Hi Ryan,
thanks for the help but your code generates a matrix
5 1 2 3 4 5 6 7 8
3 1 2 3 4 5 6 7 8
4 1 2 3 4 5 6 7 8
how can modify it to have a vector that looks like:
[ 5 4.8 4.6 4.4 .4.2 4 3.8 3.6 3.4 3.2 3 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4 ... ?
Also I don't have a intraday vecteur. The intraday numbers are computed using the gap between two numbers.
Ryan
Ryan 2012년 5월 31일
clear i j
elements = [5 3 4]; % Currently what you have
% Matrix containing intraday prices where each row corresponds to the intraday prices for each of the members of elements
intraday = [1 2 3 4 5 6 7 8;1 2 3 4 5 6 7 8;1 2 3 4 5 6 7 8];
j = length(elements);
for i = 1:j
newelements(i) = [elements(i),intraday(i,:)];
end
[r,c] = size(newelements);
newestelements = reshape(newelements,1,r*c);
I understand that you answered your own question, but I believe that should work. More round about than your approach though!
Charles Martineau
Charles Martineau 2012년 5월 31일
Hi Ryan,
THanks for help! I'll keep your answer in mind. The answer that I got came from StackOverflow

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

Ryan
Ryan 2012년 6월 1일

0 개 추천

that should read newelements(i,:) = [elements(i),intraday(i,:)];
it is the same as before, it just reshapes it at the end.

카테고리

도움말 센터File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by