save data to cell array
Show older comments
I need to save all this data into a cell array in order for my function to work. Can someone please assist me??
while 1
shapeList = {'Circle','Square','Ellipse','Triangle','Rectangle'};
[selection,ok] = listdlg('PromptString','Select the next shape:',...
'SelectionMode','single',...
'OKString','Enter',...
'CancelString','No more',...
'ListString',shapeList);
if ~ok
break;
end
switch selection
case 1
shape='Circle';
case 2
shape='Square';
case 3
shape='Ellipse';
case 4
shape='Triangle';
case 5
shape='Rectangle';
end
shapecounter=shapecounter+1;
switch selection
case 1
prompt={'Enter diameter'};
case 2
prompt={'Enter side length dimension'};
case 3
prompt={'Enter major diameter','Enter minor diameter'};
case 4
prompt={'Enter base dimension', 'Enter height dimension'};
case 5
prompt={'Enter height', 'Enter width'};
end
firstdim=str2num(inputvalues{1});
if length(inputvalues)> 1
seconddim=str2num(inputvalues{2});
end
if isempty(ok)
colour='No_Colour';
else
switch selectionC
case 1
colour='Red';
case 2
colour='Yellow';
case 3
colour='Blue';
case 4
colour='Green';
case 5
colour='Orange';
case 6
colour='Violet';
otherwise
colour='No_Colour';
end
end
switch selection
case 1
area=pi*(firstdim/2)^2;
case 2
area=firstdim^2;
case 3
area=pi*(firstdim/2)*(seconddim/2);
case 4
area=0.5*firstdim*seconddim;
case 5
area=firstdim*seconddim;
end
end
Print_Me(shape);
2 Comments
Mohammad Sami
on 1 Apr 2020
you either use the {} to store things in cell array
e.g.
a = {shape colour area};
or you can create a cell array and use index to store
a = cell(1,3);
a{1} = shape;
a{2} = colour;
a{3} = area;
Avery Kettlewell
on 1 Apr 2020
Accepted Answer
More Answers (0)
Categories
Find more on Surfaces, Volumes, and Polygons in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!