MATLAB: Quick way to reference an index of values inside one array column like blitzer(:,5) without having to create an entirely new vector?
-
I want to reference an index of values inside the 5th column of an array like blitzer. E.g. I want to access, say, all values of blitzer(:,5) where blitzer(:,4) < 10. This outputs an index of values. So maybe I could set blitzer5 = blitzer(:,5), and then call blitzer5(blitzer(:,4) < 10). But is there a quick way to do this without having to create an entirely new vector? Ideally I'd like to call blitzer(:,5)[blitzer(:,4) < 10]. If so, how?
-
Answer:
Yes, just remember that the inequality simply yields a linear index, which can be used to replace ":" in the first dimension of your matrix. >> blitzer=rand(5,5) blitzer = 0.8147 0.0975 0.1576 0.1419 0.6557 0.9058 0.2785 0.9706 0.4218 0.0357 0.1270 0.5469 0.9572 0.9157 0.8491 0.9134 0.9575 0.4854 0.7922 0.9340 0.6324 0.9649 0.8003 0.9595 0.6787 >> blitzer(blitzer(:,4)<0.5,5) ans = 0.6557 0.0357 >> blitzer(:,4)<0.5 ans = 1 1 0 0 0
Achilleas Vortselas at Quora Visit the source
Related Q & A:
- How to save values to an array?Best solution by Stack Overflow
- Which one do u like better hollywood or bollywood?Best solution by Yahoo! Answers
- What is a quick way to get rid of a breakout on my face?Best solution by Yahoo! Answers
- What is a quick way to improve my vertical jump?Best solution by Yahoo! Answers
- How do you get a quick,new email via MSN without deleting original email?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.