Skip to content

Commit f0d4618

Browse files
committed
fix UnfoldVectorImage.m (unfold method now returns Table instance)
1 parent 990a28b commit f0d4618

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

ImageM/+imagem/+actions/+image/UnfoldVectorImage.m

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,16 @@ function run(obj, frame) %#ok<INUSL>
4444
return;
4545
end
4646

47+
% default table name
48+
tableName = 'Channels';
49+
if ~isempty(img.Name)
50+
tableName = [img.Name '-Channels'];
51+
end
52+
4753
% creates a new dialog, and populates it with some fields
4854
gd = imagem.gui.GenericDialog('Unfold Vector Image');
49-
addChoice(gd, 'Plot Type: ', {'line', 'bar', 'stem', 'stairSteps'}, 'line');
55+
addTextField(gd, 'Table Name: ', tableName);
56+
addChoice(gd, 'Channel Plot Type: ', {'line', 'bar', 'stem', 'stairSteps'}, 'line');
5057
addCheckBox(gd, 'Create Coords Table', false);
5158

5259
% displays the dialog, and waits for user
@@ -57,58 +64,41 @@ function run(obj, frame) %#ok<INUSL>
5764
end
5865

5966
% parse the user inputs
67+
tableName = getNextString(gd);
6068
type = getNextString(gd);
6169
createCoordsTable = getNextBoolean(gd);
6270

6371
% unfold the table
64-
[data, colNames, coords] = unfold(img);
65-
tab = Table(data, colNames);
72+
[tab, coords] = unfold(img);
73+
tab.Name = tableName;
6674
nc = size(tab, 2);
6775
tab.PreferredPlotTypes = repmat({type}, 1, nc);
6876

69-
% create table axis that corresponds to image axis
70-
indC = findChannelAxes(img);
71-
imAxis = img.Axes{indC};
72-
if isa(imAxis, 'image.axis.NumericalAxis')
73-
values = indexToPosition(imAxis, 1:nc);
74-
axis = table.axis.NumericalAxis(imAxis.Name, values);
75-
tab.Axes{2} = axis;
76-
77-
elseif isa(imAxis, 'image.axis.CategoricalAxis')
78-
axis = table.axis.CategoricalAxis(imAxis.Name, imAxis.Names);
79-
tab.Axes{2} = axis;
80-
81-
else
82-
warning(['Unknown type of axis in image: ' class(imAxis)]);
83-
end
84-
85-
8677
% create table viewer
8778
[newFrame, newDoc] = createTableFrame(frame.Gui, tab, frame); %#ok<ASGLU>
8879
newDoc.ImageSize = size(img, 1:ndims(img));
8980

90-
% add to history
91-
string = sprintf('[tab, names, coords] = unfold(%s);\n', doc.Tag);
92-
addToHistory(frame, string);
93-
string = sprintf('%s = Table(tab, names});\n', newDoc.Tag);
94-
addToHistory(frame, string);
95-
9681
% also create a table for coordinates if requested
9782
if createCoordsTable
9883
if ndims(img) == 2 %#ok<ISMAT>
9984
coordNames = {'x', 'y'};
100-
coordStr = '{''x'', ''y''}';
10185
elseif ndims(img) == 3
10286
coordNames = {'x', 'y', 'z'};
103-
coordStr = '{''x'', ''y'', ''z''}';
10487
end
10588
coordsTable = Table(coords, coordNames);
10689
[coordsFrame, coordsDoc] = createTableFrame(frame.Gui, coordsTable); %#ok<ASGLU>
107-
108-
% add to history
109-
string = sprintf('%s = Table(coords, %s});\n', coordsDoc.Tag, coordStr);
90+
end
91+
92+
% add to history
93+
if createCoordsTable
94+
string = sprintf('[%s, %s] = unfold(%s);\n', ...
95+
newDoc.Tag, coordsDoc.Tag, doc.Tag);
96+
addToHistory(frame, string);
97+
else
98+
string = sprintf('%s = unfold(%s);\n', newDoc.Tag, doc.Tag);
11099
addToHistory(frame, string);
111100
end
101+
112102
end
113103

114104
end % end methods

0 commit comments

Comments
 (0)