0

I have the following (simplified) data file:

# Created on Fri Aug 27 16:48:30 2021
# name: M
# type: matrix
# rows: 5
# columns: 5

0 0 0 0 0 
0 5 0 0 0 
0 4 0 0 0 
0 4 0 0 0 
0 4 0 0 0 

0 1 0 0 0 
1 0 1 0 0 
0 5 0 0 0 
0 4 0 0 0 
0 4 0 0 0 

0 1 0 0 0 
1 1 1 0 0 
1 0 1 0 0 
0 5 0 0 0 
0 4 0 0 0 

0 1 0 0 0 
1 1 1 0 0 
1 1 1 0 0 
1 0 1 0 0 
0 5 0 0 0

I need to use GNU Octave to plot these data as a 2D XY surface and be able to scroll across the Z axis.

This is what I did so far:

clf;
colormap ("default");

# Load data file in matrix M
load "./toy.data"

# Axes range
x = 0:columns(M);
y = 0:rows(M);

h = imagesc (x, y, M);

The result is what I expect; the only issue is that only the first XY slice is shown.

How can I make Octave read the next blocks, and shown them when I press two keys or when I move the mouse pointer to go back and forth with respect to my actual position?


With Tasos suggestion, I updated the file which now includes a slider and a (still empty) callback:

clf;
colormap ("default");

# Load data file in matrix M
load "./toy.data"

# Axes range
x = 0:columns(M);
y = 0:rows(M);

h = imagesc (x, y, M);

%% Add ui 'slider' element
hslider = uicontrol (                    ...
       'style', 'slider',                ...
       'Units', 'normalized',            ...
       'position', [0.1, 0.1, 0.8, 0.1], ...
       'min', 1,                         ...
       'max', 5,                         ...
       'value', 1,                       ...
       'callback', {@updateTime}         ...
     );

%% Callback function called by slider event to change time frame
function updateTime (h, event)
     %% TODO - Update CData
end
Pietro
  • 12,086
  • 26
  • 100
  • 193
  • 1
    Do something similar to [this](https://stackoverflow.com/a/43536882/4183191), but instead of plotting, use imagesc appropriately. Even better, use imagesc only once, and at each callback simply update the cdata of the existing image. This will be more efficient. – Tasos Papastylianou Aug 27 '21 at 20:14
  • @TasosPapastylianou - From your example, I could add the slider to my plot, and the (dummy for now) callback function is correctly called. However, how should I update the CData value? How can I let Octave know it has to read the next matrix (next z value) in the data file? – Pietro Aug 28 '21 at 16:07
  • 1
    If you capture your plot object at the time of plotting (e.g. `p = plot(...)` ), then you can set the `cdata` attribute (or any attribute in general) by doing `set( p, 'cdata', [ (...new data) ])`. To get a list of all possible attributes that can be accessed, do `get( p, '' )`. – Tasos Papastylianou Sep 01 '21 at 10:18

0 Answers0