How do I show rows and columns from a matrix in a edit texted in MATLAB?

7 visualizaciones (últimos 30 días)
Hello everyone,
I'm still working on my project and I'm stuck again, please someone if could help me with thiss problem...
I want to show a matrix that contains a lot of columns and rows in a GUI and I don't know how to arrange that.
This is the matrix in the comand window: https://imgur.com/a/NeAYzXW
And this is how its show me in the interface: https://imgur.com/a/BR7aoSH
And this is the code:
MAIN PROGRAM:
s3 = ['[',regexprep(num2str(Vc),' +',' '),']'];
interfVc(s3);
INTERFACE PROGRAM:
function interfVc(s3)
%Manipularea figurii
figure('Name','CODARE/DECODARE TORNADO',...
'Units','normalized',...
'Color','white',...
'Position',[0.1,0.1,0.8,0.8]);
%'Elementele matricii de codare liniara Tornado [Vc]'
uicontrol('Style','Text',...
'Units','Normalized',...
'Position',[0.11,0.9,0.35,0.06],...
'BackgroundColor',[1,1,1],...
'FontSize',12,...
'FontWeight','b',...
'String','Elementele matricii de codare liniara Tornado [Vc]');
uicontrol('Style','Edit',...
'Units','Normalized',...
'Position',[0.11,0.4,0.7,0.5],...
'FontSize',10,...
'String',s3,...
'Callback','Vc=str2num(get(gco,''String''));interfVc(s3)');
Thank you.

Respuesta aceptada

Adam Danz
Adam Danz el 13 de Ag. de 2019
Your matrix does not contains many rows. In fact, it's a row vector so it only contains 1 row. You can see this in your first image. Also this line would break if Vc had multiple rows: s3 = ['[',regexprep(num2str(Vc),' +',' '),']'];
So, the row vector is appearing correctly. If you'd like to reshape the vector into a matrix, please describe those intentions.
  21 comentarios
Demeter Andreea
Demeter Andreea el 19 de Ag. de 2019
So I made it a function now:
%Figura Codare TORNADO
%--------------------------------------------------------------------------
function FiguraVc(~, ~)
figure()
set(gcf,'color','Black'); %setare background
%'Elementele matricii de codare liniara Tornado [Vc]'
uicontrol('Style','Text',...
'Units','Normalized',...
'Position',[0.1,0.6,0.5,0.4],...
'BackgroundColor',[0,0,0],...
'FontSize',12,...
'ForegroundColor','White',...
'FontWeight','b',...
'FontName','Consolas',...
'String','Elementele matricii de codare liniara Tornado [Vc]');
%Tabloul de valori
uicontrol('Style','Edit','Units','Normalize','position',[.1,.5,.6,.4],...
'Max',2,'String',num2str(Vc),'FontName', 'Consolas');
end
This is the callback-ul:
%PushButton Vc
uicontrol('Style','PushButton',...
'Units','normalized',...
'BackgroundColor',[0.0,0.0,0.0],...
'FontSize',8,...
'FontWeight','b',...
'ForegroundColor','W',...
'FontName','Consolas',...
'String','Matrice codare [Vc]',...
'Position',[0.08,0.15,0.12,0.08],...
'Callback',{@FiguraVc} );
The problem now is that its now showing me this part from code
%Tabloul de valori
uicontrol('Style','Edit','Units','Normalize','position',[.1,.5,.6,.4],...
'Max',2,'String',num2str(Vc),'FontName', 'Consolas');
It's showing me this when I press the button:
I don t see the tables anymore with the values of Vc and its givin me this error:
Undefined function or variable 'Vc'.
Error in FiguraVc (line 19)
'Max',2,'String',num2str(Vc),'FontName', 'Consolas');
Error while evaluating UIControl Callback
Adam Danz
Adam Danz el 19 de Ag. de 2019
Try to troubleshoot this and understand what the problems are. You're talented and with a little investigation I believe you can do this and you'll learn so much in that process. If you get an error, google that error and read about it to understand it. Use the matlab documentation to understand functions and their inputs/outputs. I can check back later to chip in, after doing some of my own work.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by