1

I Have a 8x18 structure with each cel containing a column vector of occurrences of a single event. I want to obtain data from some of these fields concatenated in a single array, without having to loop through it. I can't seem to find a way to vertically concatenate the fields I am interested in in a single array.

As an example I create the following structure with between 1 and 5 occurrences per cell:

s(62).vector(8,18).heading.occurrences=[1;2;3];
for i=1:62
    for j=1:8
        for k=1:18
            y=ceil(rand(1)*5);
            s(i).vector(j,k).heading.occurrences=rand(y,1);
        end
    end
end

Now i want to obtain all occurrences in several cells while keeping i constant at for instant i=1. What I have tried is:

   %fields of interest
   a=[1 26 45];
   x=[s(1).vector(a).heading.occurrences];

This however yields the error: Expected one output from a curly brace or dot indexing expression, but there were 3 results.

Is there anyone how to do this without having to loop through the whole structure?

Jasper
  • 75
  • 5

1 Answers1

1

Here you go:

ss=s(1).vector([1 26 45]);                     
h=[ss.heading];            
cell2mat({h.occurrences}')
Jed
  • 193
  • 11
  • Works like a charm thank you very much Jed! :) If I would want to do the same for s, for instance s([1 2 3]).vector([1 26 45]), how would that work? I have tried xx=s([1 2 3]), yy=xx.vector([1 26 45]) but that gives me the same error. Is this also possible with a vector operation? – Jasper Jun 17 '17 at 14:43
  • @Jasper Please avoid asking a new question as a comment. Either accept this answer and create a new question mentioning your previous related question or edit your question to include all the necessary information to answer your question, but avoid asking multiple distinct questions at once. – m7913d Jun 18 '17 at 11:01
  • Excuse me, I am new to this forum. I have updated my question – Jasper Jun 18 '17 at 12:42