How to interpolate intermediate values?

I have an array with 110 values. let say:
M1_allvalues = [1,2,10,-1,-2,..,-10, 1, 2..........,10]
I simply want to make the array to a size of 3600 values in it, by interpolating the values in between each array element. There would be approximately 32-33 values between each element to achieve 3600 values array. For example:
Between 1 and 2 in the given array some 32 values, then the beginning would be:
newArray = [1, 1.03, 1.06, 1.09........,1.97, 2,......, 3,........, 110]
How do I do that? I was thinking of this:
for i=1:length(M1_allvalues) - 1
newArray(i,1)= M1_allvalues(i,1): (32-33 vales): M1_allvalues(i + 1,1);
end
could you me some idea?

2 个评论

Is it required that the existing elements all appear in the output exactly? If equal spacing were used then some elements might only be approximated.
@Walter Roberson Yes. Because they represent a curve. If we consider only the start and end the curve will not be thereafter. In other words, upsampling may be. The array look like as follows. For instance, I would like to have between -0.716515302 and -0.738227694 I would like to have 32/33 values. The similar way for all. Do we have any inbuild function for that?
M1_allvalues = [
-0.716515302
-0.738227694
-0.734134713
-0.795537839
-0.721594973
-0.733554246
-0.633938598
-0.646957164
-0.639987555
-0.650192438
-0.69239733
-0.844869671
-0.891111276
-0.97870424
-0.97912141
-0.87953858
-0.87995575
-0.98037292
-0.98079009
-0.98120726
-0.98162443
-0.9820416
-0.982458771
-0.982875941
-0.983293111
1.014964305
0.98042719
0.974544314
0.688186533
0.658870952
0.595105523
0.390863794
0.199207123
0.215257305
0.10254977
-0.051655171
-0.234441557
-0.306198555
-0.304774991
-0.420750606
-0.559915604
-0.507888071
-0.64621695
-1.025155038
-0.515321439
-0.672936192
-0.620544176
-0.660977732
-0.673011345
-0.785923311
-0.607349152
-0.580663475
-0.63031181
-0.765443108
-0.662154214
-0.646247998
-0.628825981
-0.625081084
-0.618565838
-0.661108932
-0.645737598
-0.606520318
-0.639491009
-0.653300752
-0.670253078
-0.659396223
-0.778644332
-0.870010559
-0.939977168
-0.941245761
-0.942514355
-0.943782948
-0.945051542
-0.946320136
-0.947588729
-0.948857323
-0.950125916
-0.95139451
-0.952663103
-0.953931697
1.102059236
0.800832245
0.878517853
0.771312906
0.682760904
0.524194329
0.845499176
0.780904075
0.185449607
0.08183194
0.005542497
-0.129033531
-0.230487187
-0.316896749
-0.413027888
-0.507425914
-0.599394836
-0.616839434
-0.63656488
-0.669927747
-0.668568359
-0.646474955
-0.646278772
-0.582780115
-0.735585371
-0.772032042
-0.757837306
-0.734415844
-0.740307607
-0.74551905 ]

请先登录,再进行评论。

 采纳的回答

KSSV
KSSV 2018-6-21
编辑:KSSV 2018-6-21
% M1_allvalues = [1,2,3,....,110] ;
iwant = linspace(min(M1_allvalues),max(M1_allvalues ),3600) ;

3 个评论

Hallo KSSV thanks for your answer. But I have following data set:
M1_allvalues = [
-0.716515302
-0.738227694
-0.734134713
-0.795537839
-0.721594973
-0.733554246
-0.633938598
-0.646957164
-0.639987555
-0.650192438
-0.69239733
-0.844869671
-0.891111276
-0.97870424
-0.97912141
-0.87953858
-0.87995575
-0.98037292
-0.98079009
-0.98120726
-0.98162443
-0.9820416
-0.982458771
-0.982875941
-0.983293111
1.014964305
0.98042719
0.974544314
0.688186533
0.658870952
0.595105523
0.390863794
0.199207123
0.215257305
0.10254977
-0.051655171
-0.234441557
-0.306198555
-0.304774991
-0.420750606
-0.559915604
-0.507888071
-0.64621695
-1.025155038
-0.515321439
-0.672936192
-0.620544176
-0.660977732
-0.673011345
-0.785923311
-0.607349152
-0.580663475
-0.63031181
-0.765443108
-0.662154214
-0.646247998
-0.628825981
-0.625081084
-0.618565838
-0.661108932
-0.645737598
-0.606520318
-0.639491009
-0.653300752
-0.670253078
-0.659396223
-0.778644332
-0.870010559
-0.939977168
-0.941245761
-0.942514355
-0.943782948
-0.945051542
-0.946320136
-0.947588729
-0.948857323
-0.950125916
-0.95139451
-0.952663103
-0.953931697
1.102059236
0.800832245
0.878517853
0.771312906
0.682760904
0.524194329
0.845499176
0.780904075
0.185449607
0.08183194
0.005542497
-0.129033531
-0.230487187
-0.316896749
-0.413027888
-0.507425914
-0.599394836
-0.616839434
-0.63656488
-0.669927747
-0.668568359
-0.646474955
-0.646278772
-0.582780115
-0.735585371
-0.772032042
-0.757837306
-0.734415844
-0.740307607
-0.74551905 ]
Your answer, therefore, can not be applied here, unfortunately.
Let A be your data.
N = round(3600/length(A)) ;
iwant = zeros(N,length(A)-1) ;
for i = 1:length(A)-1
iwant(:,i) = linspace(A(i),A(i+1),N) ;
end
iwant = iwant(:) ;
Yes.. That works.... Thanks a lot

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by