Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How to extract the same row, column 2 value by inputting the column 1 value

1 Ansicht (letzte 30 Tage)
Corey McMullen-Burn
Corey McMullen-Burn am 18 Okt. 2020
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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'];

Antworten (1)

Jemima Pulipati
Jemima Pulipati am 21 Okt. 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
NOTE : You can customize how the numbers are displayed using the Format Output in MATLAB.

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by