Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Upsampling by duplicating existing data?

Subject: Upsampling by duplicating existing data?

From: Jamie Barron

Date: 7 Apr, 2011 09:45:57

Message: 1 of 5

I've got a vector that I'd like to duplicate each point, upsample
doesn't handle this as it adds zeros. Can anybody point me to the
quickest way to achieve this?

Initial: [1;2;3]
Wanted: [1;1;2;2;3;3]

If I use upsample, I obviously get [1;0;2;0;3;0] - I can go through this
and copy each element, but it seems inefficient?

Subject: Upsampling by duplicating existing data?

From: Sadik

Date: 7 Apr, 2011 10:12:04

Message: 2 of 5

Hi Jamie,

initial = [1;2;3];
upsamplingFactor = 2;

wanted = repmat(initial',[upsamplingFactor 1]);
wanted = wanted(:);

Best.

Subject: Upsampling by duplicating existing data?

From: ImageAnalyst

Date: 7 Apr, 2011 10:19:20

Message: 3 of 5

imresize (in the Image Processing Toolbox) will also do it if you use
its 'nearest' option.

Subject: Upsampling by duplicating existing data?

From: Jamie Barron

Date: 7 Apr, 2011 10:27:02

Message: 4 of 5

On 07/04/2011 11:12, Sadik wrote:
> Hi Jamie,
>
> initial = [1;2;3];
> upsamplingFactor = 2;
>
> wanted = repmat(initial',[upsamplingFactor 1]);
> wanted = wanted(:);
>
> Best.

Hi Sadik,

That seems to work, thanks!

Can I ask what the "wanted = wanted(:);" line does please? It seems to
be sorting it, but I don't know why.

Thanks.

Subject: Upsampling by duplicating existing data?

From: Sadik

Date: 7 Apr, 2011 11:05:07

Message: 5 of 5

Actually it is nothing fancy. repmat produced a matrix, but the desired output is a vector so we are vectorizing the matrix "wanted". When A is a matrix, A(:) is a vector with A's columns put one after the other.

Best.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us