%I_Phase [0 51.1111 102.2222 153.3333 204.4444 255.5556 306.6667 357.7778 408.8889 460]
%Theta [-45 -30 -15 0 15 30 45 60 75 90]
%Torque_Matrix [0 0 0 0 0 0 0 0 0 0 28.6989 35.9452 41.1581 43.8173 43.5092 40.0174 33.4011 24.0388 12.6221 0.0940 52.6956 67.7241 79.8022 87.4465 89.2066 84.0131 71.5044 52.2439 27.7582 0.3762 71.9900 95.3367 115.9323 130.8876 137.0923 131.9869 114.3100 84.6153 45.4083 0.8464 86.5822 118.7830 149.5483 174.1406 187.1661 183.9389 161.8178 121.1530 65.5724 1.5047 96.4722 138.0630 180.6504 217.2055 239.4282 239.8691 214.0278 161.8569 88.2505 2.3511 101.6600 153.1768 209.2385 260.0824 293.8785 299.7776 270.9400 206.7272 113.4425 3.3856 102.1456 164.1242 235.3126 302.7711 350.5170 363.6642 332.5544 255.7637 141.1486 4.6082 97.9289 170.9054 258.8727 345.2718 409.3438 431.5290 398.8711 308.9666 171.3687 6.0188 89.0100 173.5203 279.9188 387.5844 470.3588 503.3720 469.8900 366.3357 204.1028 7.6176]
我有两个向量(I_Phase1, Theta1)
和一个矩阵(Torque_Matrix)
,我需要用interp2
进行插值,但运行interp2时我的函数和循环,Theta_Int和I_Phase_Int值是只有90和460,所以我只有一个Torque_Value的值,我需要-45:90和0:460的值,我需要创建一个具有Torque_Values值的新数组。我需要帮助。
surf(Theta1,I_Phase1,Torque_Matrix);
hold on
Matrix_int = zeros(100);
index_Theta = 0;
index_I = 0;
for Theta_Int = -45:90;
for I_Phase_Int = 0:460;
Torque_Value = interp2(Theta1,I_Phase1,Torque_Matrix,Theta_Int,I_Phase_Int);
end
end
surf(Theta_Int,I_Phase_Int,Torque_Value,'.r');
答案 0 :(得分:0)
您可以将interp2函数与向量一起使用,但如果它对您自己的初学者有帮助,可以看到每个步骤中发生了什么,for循环仍然有效。您只需要为Theta_Int和I_Phase_Int创建向量。然后,当您调用interp2时,将索引Theta_Int(j)和I_Phase_Int(k),并将值存储在Torque_Value(k,j)中。我交换了for循环,所以当你进行冲浪时,它会沿着与上面相同的轴绘制。
$ # to insert before first line
$ cat f1 ip.txt
"desc_test":[
"id",
"name",
],
1
2
3
$ # to insert any other line number, use line_num-1
$ # for example, to insert before 2nd line, use 1r
$ # r command will read entire contents from a file
$ sed '1r f1' ip.txt
1
"desc_test":[
"id",
"name",
],
2
3
还创建了一个新图,以便显示两个图。所以只需用这段代码替换你的for循环就可以了。它可以工作。