How can I fill a vector with another one with different size?

조회 수: 5 (최근 30일)
bkshn
bkshn 2015년 7월 25일
답변: Mendi 2015년 7월 25일
Hello
I want to fill a vector with another vector with different size. like bellow example, that "fullPath" is 201*1 and "xpath" size is 100*1.
fullPath(1:2:end)=2*(xpath(1:1:end));
I have this error : In an assignment A(I) = B, the number of elements in B and I must be the same.
Could you help me?
Thanks alot

채택된 답변

Image Analyst
Image Analyst 2015년 7월 25일
Try this:
fullPath(1:length(xpath)) = 2 * xpath;
If you want the left-most elements assigned. Or if you want every other one to be assigned (like it seems like you tried to do), try this:
fullPath(1:2:2*length(xpath)) = 2 * xpath;

추가 답변 (1개)

Mendi
Mendi 2015년 7월 25일
To find the error source run:
length(xpath(1:1:end)) %=100
length(fullPath(1:2:end)) %=101
So change the code to:
fullPath(1:2:end-1)=xpath(1:1:end);

카테고리

Help CenterFile Exchange에서 Structured Data and XML Documents에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by