How do you use values from an array as serial numbers to extract values from a different array?
Mostrar comentarios más antiguos
If I am using an array to record values such as [0:10:100], then how can I create a column vector containing values extracted from a table(with two columns, one of which is the independent variable and the other is the dependent variable) with the intervals 0, 10, 20,...,100?
Respuestas (1)
Star Strider
el 17 de Oct. de 2020
It is not possible to reference ‘row 0’ since MATLAB subscripts begin at 1.
I am not certain what you want, so see if this short example works for you:
T1 = array2table(randi(100, 35, 2)); % Create Random Table
T2ext = T1([1 10:10:30],:); % Extract Rows
.
4 comentarios
Vedeesh Bali
el 17 de Oct. de 2020
Star Strider
el 17 de Oct. de 2020
I am still not exactly certain what result you want.
Try this:
M = [15:150; rand(size(15:150))].' % Create Matrix
vfit = 15:5:150; % Create 1vfit’
Lv = ismember(M(:,1), vfit); % Logical Vector
Out = [vfit(:) M(Lv, 2)] % Result
Note that this assumes that the array (here ‘M’) is a (136x2) matrix.
Vedeesh Bali
el 18 de Oct. de 2020
Star Strider
el 18 de Oct. de 2020
yi = interp1(x, y, vfit)
Out = [vfit, yi]
That will likely produce the result you want, even though I still have no idea what that is. Note that for this to work, both ‘x’ and ‘vfit’ must be monmotonically either increasing or decreasing, and both must go in the same direction.
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!