Filter löschen
Filter löschen

How to use interp2 to resize arrays of different sizes?

15 Ansichten (letzte 30 Tage)
Hello,
I have an excel sheet test data with results in individual sheets. I am plotting two columns in each sheets. But the array sizes are not exactly the same in all sheets. For example: - In sheet 1- My test datas are of the size 1202x2 - In sheet 2- My test datas are of the size 1752x2 - In sheet 3- My test datas are of the size 1402x2 How can I use interp2 to resize the bigger ones to the size of 1202x2. I was able to do with interp1 individually but it would be better if I implement interp2?
Thanks a lot in advance.
  1 Kommentar
Adam
Adam am 7 Jul. 2017
You should just be able to do it similarly to interp1, but set the output size the same as the input size in the y direction

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

dpb
dpb am 7 Jul. 2017
Not sure it will actually be any faster than using interp1 by column for only two columns and will certainly be far more memory intensive to build the grid interp2 needs but the technique is
targetSize = size(Sheet1Vector); % would be 1202x2 here
sourceSize = size(SheetNVector); % 1752x2 for second series
[X,Y] = meshgrid(linspace(1,sourceSize(2),targetSize(2)), ...
linspace(1,sourceSize(1),targetSize(1))); % build the interpolant grid
New2DArray=interp2(x,X,Y); % interpolate each x in turn
For just an easy example to see...use a small test dataset
>> x=rand(12,2);
>> ts=[10 2];
>> [X Y]=meshgrid(linspace(1,2,2),linspace(1,12,10))
X =
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
Y =
1.0000 1.0000
2.2222 2.2222
3.4444 3.4444
4.6667 4.6667
5.8889 5.8889
7.1111 7.1111
8.3333 8.3333
9.5556 9.5556
10.7778 10.7778
12.0000 12.0000
>> interp2(x,X,Y)
ans =
0.9836 0.6382
0.9138 0.2984
0.4237 0.6975
0.6539 0.7978
0.1446 0.7331
0.9451 0.5553
0.5568 0.1249
0.2970 0.1182
0.8009 0.3741
0.0561 0.0216
>> whos ans
Name Size Bytes Class Attributes
ans 10x2 160 double
For this special case, you can easily build the X, Y arrays by inspection and only Y will change from sheet to sheet; just showed the general form where both X and Y could be variable.
There's a function imresize in the Image Processing toolbox that does this in one call if you happen to have that...
  1 Kommentar
Swaminath VENKATESWARAN
Swaminath VENKATESWARAN am 11 Jul. 2017
Hello,
Many thanks for your support. It was really useful. But the thing was it took some time. Actually I found another way using interp1. I assigned my required x-y values to be resized into cells. I extract the cell which has the least size and move it to the last position, take it as reference and with the help of 'for' loop I implement interp1 on the other cells. It looks bit lengthy but was very effective. Thanks a lot for your support again.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by