Info
This question is closed. Reopen it to edit or answer.
How to extract the same row, column 2 value by inputting the column 1 value
1 view (last 30 days)
Show older comments
I have created a matix from a smoothed spline interpolation called SS(see below), I now need to be able to have matlab reference the T value from the same row in that matrix when it is given an x value how can I do this?
clc
clear
lengthX = 100;
x=[0 20 40 60 65 70 75 80 85 90 95 100]';
T=[150 176 212 268 282 289 296 290 262 200 100 0]';
samplingRateIncrease = 395.89;
newXSamplePoints = linspace(1, lengthX, lengthX * samplingRateIncrease);
smoothedT = spline(x, T, newXSamplePoints);
x1= 1.57*newXSamplePoints;
Tm1 = 100.519*smoothedT;
SS = [Tm1', x1'];
0 Comments
Answers (1)
Jemima Pulipati
on 21 Oct 2020
From my understanding, you want to print the corresponding Tm1 value of a specific x1 value from the SS matrix.
Here is a sample code.
clc
clear
lengthX = 100;
x=[0 20 40 60 65 70 75 80 85 90 95 100]';
T=[150 176 212 268 282 289 296 290 262 200 100 0]';
samplingRateIncrease = 395.89;
newXSamplePoints = linspace(1, lengthX, lengthX * samplingRateIncrease);
smoothedT = spline(x, T, newXSamplePoints);
x1= 1.57*newXSamplePoints;
Tm1 = 100.519*smoothedT;
SS = [Tm1', x1'];
% calculating index of rows with a specific column value
% here a hardcoded x1 value is provided as the specific column value
index = SS(:,2) == 1.573926189754471;
% printing the corresponding Tm1 value
SS(index,1)
This code checks for the index of rows which have the column values as '1.573926189754471' and prints the Tm1 values of those rows. Since the values of SS matrix are unique there would be only one Tm1 value displayed always.
The result of the above code is
ans =
1.5208e+04
You can refer to this link for more information on how to perform Matrix indexing
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!