How to add images in appdesigner?

조회 수: 20 (최근 30일)
Ali Deniz
Ali Deniz 2022년 5월 6일
댓글: Parsa 2022년 5월 10일
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
UITable matlab.ui.control.Table
ReadDataButton matlab.ui.control.Button
ReadGuidanceButton matlab.ui.control.Button
GuidanceTextAreaLabel matlab.ui.control.Label
GuidanceTextArea matlab.ui.control.TextArea
FuseTextAreaLabel matlab.ui.control.Label
FuseTextArea matlab.ui.control.TextArea
ReadFuseButton matlab.ui.control.Button
Image matlab.ui.control.Image
end
% Callbacks that handle component events
methods (Access = private)
% Cell edit callback: UITable
function UITableCellEdit(app, event)
indices = event.Indices;
newData = event.NewData;
end
% Button pushed function: ReadDataButton
function ReadDataButtonPushed(app, event)
t = readtable("Kitap1.xlsx","Sheet",1);
app.UITable.Data = t;
app.UITable.ColumnName = t.Properties.VariableNames;
end
% Button pushed function: ReadGuidanceButton
function ReadGuidanceButtonPushed(app, event)
t = readtable("Kitap1.xlsx","Sheet",1);
app.UITable.Data = t;
app.UITable.ColumnName = t.Properties.VariableNames;
%t=t(strcmp(t.Guidance,app.GuidanceTextArea.Value),:);
%t=t(startsWith(t.Guidance,app.GuidanceTextArea.Value),:);
t=t(contains(t.Guidance,app.GuidanceTextArea.Value),:);
app.UITable.Data=t;
end
% Button pushed function: ReadFuseButton
function ReadFuseButtonPushed(app, event)
t = readtable("Kitap1.xlsx","Sheet",1);
app.UITable.Data = t;
app.UITable.ColumnName = t.Properties.VariableNames;
%t=t(strcmp(t.Fuse,app.FuseTextArea.Value),:);
%t=t(startsWith(t.Fuse,app.FuseTextArea.Value),:);
t=t(contains(t.Fuse,app.FuseTextArea.Value),:);
app.UITable.Data=t;
end
% Image clicked function: Image
function ImageClicked(app, event)
end
end
I have this code and this app. When I clicked Read Data, excel datas comes. But I want to images. For example when I clicked on one of the data as seen in the figure, I want the photo of the clicked one in the image location at the right. How can I do that? Thank you.

채택된 답변

Parsa
Parsa 2022년 5월 6일
편집: Parsa 2022년 5월 6일
Hi Ali,
I think you should use ‘UITableCellSelection’ callback function, so that a command (such as showing an image), promptly executed after selecting the desired cell.
In addition I think it should be necessary to ‘global’ the table ‘t’, in both ‘ReadDataButtonPushed'and ‘UITableCellSelection’ functions , in order that being able to read the desired cell of the table.
Here I share a simple app with you, as the same as yours, which is a table contains bearing names and corresponding equipment. When you click on any cells in the first column, belonging to bearing’s name, the image will be shown on the axis.
% Button pushed function: ReaddataButton
function ReaddataButtonPushed(app, event)
global t
t = readtable("brg.xlsx","Sheet",1);
app.UITable.Data = t;
app.UITable.ColumnName = t.Properties.VariableNames;
% assignin('base','BrgTable',t)
end
% Cell selection callback: UITable
function UITableCellSelection(app, event)
global t
indices = event.Indices;
n=indices(1);
if strcmp(t.Bearing{n},'SKF6203')
cla(app.UIAxes)
imshow('SKF6203.jpg','Parent',app.UIAxes)
elseif strcmp(t.Bearing{n},'SKF6205')
cla(app.UIAxes)
imshow('SKF6205.jpg','Parent',app.UIAxes)
elseif strcmp(t.Bearing{n},'SKF22315')
cla(app.UIAxes)
imshow('SKF22315.jpg','Parent',app.UIAxes)
end
end
You could find the whole app, table in .xlsx format and image files in the attachment.
I also recommend taking a look at the link below, and the answer by @Kevin Holly .
Best
Parsa
  댓글 수: 2
Ali Deniz
Ali Deniz 2022년 5월 9일
Thank you very much. This information is very helpful and instructive.
Best regards
-Ali
Parsa
Parsa 2022년 5월 10일
It's my pleasure

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by