Input to Struct Array
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have been playing around with structs in Matlab all day and can't seem to grasp it. I have this code:
mystruct.color = 'red', 'green', 'red', 'red'; mystruct.angles = [30,60,90,180]; mystruct.row = [];
for i=1:3, mystruct.row[i] = input('Enter row: '); end
Where I want to input values for a row and have it stored in the row field in the mystruct struct but I keep getting this error:
Error: File: StructTest.m Line: 7 Column: 19 Unbalanced or unexpected parenthesis or bracket.
What I ultimately want to do is scan an image matrix and capture the rows of certain pixels but I need to understand this first.
Any help would be greatly appreciated.
0 comentarios
Respuestas (3)
Image Analyst
el 1 de Nov. de 2012
You need to use parentheses, not brackets: mystruct.row(i) not mystruct.row[i]
Secondly
mystruct.color = 'red', 'green', 'red', 'red';
probably doesn't do what you think it does. It does not make the color member of mystruct into a cell array with 4 elements. It assigns a string element and then basically does nothing with the string literals you define, so it's the same as these 4 completely separate lines:
mystruct.color = 'red';
'green';
'red';
'red';
Perhaps you want
mystruct.color = {'red', 'green', 'red', 'red'}; % Enclosed in braces
I have no idea what you want.
0 comentarios
Andrei Bobrov
el 1 de Nov. de 2012
mystruct.color = {'red', 'green', 'red', 'red'};
mystruct.angles = [30,60,90,180];
for i1=1:3
mystruct.row(i1) = input('Enter row: ');
end
0 comentarios
Ver también
Categorías
Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!