Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Indexing Problem

Subject: Indexing Problem

From: Michael

Date: 25 Jun, 2012 17:56:07

Message: 1 of 2

Hello all,

I have a matrix 'all_counts' (29 by 8 array containing data, and some NaNs). I'm trying to graph certain parts. I'm using (I believe) logicals to do this.

I've defined:

% define location vector, to be used for cuts
src_loc = [ 1 1 2 2 3 1 1 3 2 1 2 1 3 3 1 3 1 1 1 1 3 1 1 3 1 3 1 2 2 ]; % (29 entries)
% Define actual positions
SW=src_loc==1;
NW=src_loc==2;
NE=src_loc==3;

Which all work properly when I ask MATLAB what they are.. (e.g. SW = row vector of 1's and 0's, and likewise for NW and NE). Here's the messed up part... I can try

all_counts(1,:) --- this gives a 29-by-1 column of data (good!)
all_counts(SW,:) --- this gives all data from the Southwest source position (which is what I want)

...but when I try:
all_counts(NW,:)
I get:
Index exceeds matrix dimensions.

What is going on here? I've tried 'clear all' and re-importing my 'all_counts' as well as the position definintion for SW, NW and NE. I really only get this error with the NW position (no matter which column I try to pick out) which is unlike my other positions calls (SW, NE)... how can I fix this?

Thank you for any help. If I've been unclear please just tell me how to clarify!!!

-Michael

Subject: Indexing Problem

From: Matt J

Date: 25 Jun, 2012 18:07:06

Message: 2 of 2

"Michael " <mabowles@syr.edu> wrote in message <jsa8nn$3qm$1@newscl01ah.mathworks.com>...
>
> Which all work properly when I ask MATLAB what they are.. (e.g. SW = row vector of 1's and 0's, and likewise for NW and NE). Here's the messed up part... I can try
>
> all_counts(1,:) --- this gives a 29-by-1 column of data (good!)
===============

I think you really meant to write all_counts(:,1). What you've written would have extracted a 1x8 row.



> all_counts(SW,:) --- this gives all data from the Southwest source position (which is what I want)
>
> ...but when I try:
> all_counts(NW,:)
> I get:
> Index exceeds matrix dimensions.
>
> What is going on here?
=====================

Works fine for me

>> all_counts=rand(29,8); all_counts(NW,:)

ans =

    0.2217 0.7962 0.8865 0.3909 0.3015 0.5830 0.0688 0.6718
    0.1174 0.0987 0.0287 0.8314 0.7011 0.2518 0.3196 0.6951
    0.0855 0.7212 0.5005 0.4168 0.1781 0.9827 0.7184 0.8444
    0.8010 0.6538 0.0596 0.6280 0.9991 0.3439 0.5313 0.7805
    0.9880 0.8055 0.8253 0.5479 0.1206 0.6959 0.9577 0.4735
    0.0377 0.5767 0.0835 0.9427 0.5895 0.6999 0.2407 0.1527


I would double-check the size of all_counts or NW. If this is happening inside a function, use DBSTOP to halt execution where the error is occuring. Check the dimensions of everything at that moment.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us