Further simplify a simple vectorized operation
Ältere Kommentare anzeigen
I have a row vector of values 'gridx'. For example:
gridx=[0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5]
I also have a large column vector of values P, which are to act as indices for the vector gridx.
Thus, I can sample P(:,1) and get the corresponding values fro gridx as:
P(:,2) = gridx(P(:,1));
I want to use these values to perform another operation, so I replace it with the result as:
P(:,2)=MX-P(:2);
where MX is a column vector of length P(:,1)).
This works, but I want to shorten the code as:
P(:,2)=MX-gridx(P(:,1));
Unfortunately, this does not work. What is wrong with my syntax?
Akzeptierte Antwort
Weitere Antworten (1)
Matt J
am 9 Mär. 2014
0 Stimmen
Nothing that I can see. It should work.
1 Kommentar
Christopher
am 9 Mär. 2014
Kategorien
Mehr zu Entering Commands finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!