-1

I am trying to access the first and last number in a cell array. More specifically I need the first and last X value to see how much displacement there is. I am importing a trackmate file, which is why I've added the trackmate script below (hoping it might be of some help).

The script below is the one I use; I work on a mac

addpath('/Applications/Fiji.app/scripts')

clipZ = true;
scaleT = true;
[tracks] = importTrackMateTracks('8Tracks.xml', clipZ, scaleT);
n_tracks = numel( tracks );

tracks{:,:,:};



% tracks = IMPORTTRACKMATETRACKS(file) opens the track file 'file' and
% returns the tracks in the variable 'tracks'. 'tracks' is a cell array,
% one cell per track. Each cell is made of 4xN double array, where N is the
% number of spots in the track. The double array is organized as follow: 
% [ Ti, Xi, Yi, Zi ; ...] where T is the index of the frame the spot has been
% detected in. T is always an integer. X, Y, Z are the spot spatial 
% coordinates in physical units.
Adriaan
  • 17,741
  • 7
  • 42
  • 75
traels
  • 3
  • 2
  • In a cell array `c` the first element is accessed with `c{1}` while the last is accessed with `c{end}`, and the logic is exactly the same of arrays. Is that enough for you? – Matteo Ragni Apr 17 '18 at 17:42
  • So what's your question? I see text and code, but no question, which is weird given you filled out a box prompting you to "ask a question". – Adriaan Apr 17 '18 at 17:54
  • @Adriaan the title makes me suspect the OP wants the cell content (data), not the cell. – Matteo Ragni Apr 17 '18 at 17:59
  • Weird, seems my question got cut away. Anyways, I have a 1948x1 cell array. Each of the 1948 seems to be a n*3 double array. What I need and can't figure out how to do, is acces the first and last value of each of the double arrays, of the Xi value (the text below). Another thing that seems to have gotten cut away: I am new to Matlab, and quite frankly somewhat confused. Sorry for the confusion! – traels Apr 17 '18 at 18:02
  • [Please, do more research](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) then **post what you've tried** with a **clear explanation of what isn't** working and provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). Read [How to Ask a good question](https://stackoverflow.com/help/how-to-ask). Be sure to [take the tour](https://stackoverflow.com/tour) and read [this](https://meta.stackoverflow.com/questions/347937/im-new-to-stack-overflow-what-are-some-things-i-should-do-and-what-things-wil). – adprocas Apr 17 '18 at 18:15
  • @traels I 'cut away' those things since they are considered "noise". The level you have in MATLAB is irrelevant to the problem itself, so just post the problem. Also 'any suggestions?', whilst technically a question, isn't anything we can answer, as my suggestion would be to follow the links in the previous comment, or read documentation, take a class etc. Instead, **ask a programming question** Please see: [Why is “Can someone help me?” not an actual question?](http://meta.stackoverflow.com/q/284236); same goes for "any advice?". – Adriaan Apr 17 '18 at 18:27
  • Please instead of adding information in the comments, [edit] the question to contain that information and be *descriptive*, see the links mentioned in the comments here for that. It'll make your life on Stack Overflow a lot easier. – Adriaan Apr 17 '18 at 18:28

1 Answers1

0

I think the answer is the following, and it is based upon IMPORTTRACKMATETRACKS help paragraph, even if it appears badly written (it is incongruous in dimensions for the double arrays):

tracks = importTrackMateTracks('8Tracks.xml', clipZ, scaleT);

x_displacements = zeros(length(tracks), 1);
for i = 1:length(tracks)
    current_track = tracks{i};
    first_x = current_track(1, 2);
    last_x = current_track(end, 2);
    x_displacements(i) = last_x - first_x;
end

is that what you are searching for?

Matteo Ragni
  • 2,837
  • 1
  • 20
  • 34
  • 1
    Just so you know: [`i` and `j` are built-in functions](https://stackoverflow.com/q/14790740/5211833) don't overwrite them by using them as variable names. Use `idx`, `k`, `ii` or whatever as loop index. cc @traels – Adriaan Apr 17 '18 at 18:24
  • This is a LOT personal, but I DO overwrite them by purpose. I ONLY use `1j` to refer to the imaginary unit. I do not support the use of those two definitions in Matlab environment. But this is programming taste, more than interesting stuff. I think that nothing should be bounded to a single letter, also the behavior is not consistent since `e` is not the `epx(1)` number... But again, it is personal taste. – Matteo Ragni Apr 17 '18 at 18:30