Developing GUI in MATLAB is suitable for real time application?

I am developing the GUI for real time application, But in some aspects I found MATLAB get slow during execution. I need a sincere suggestion, do I shift to C# for GUI application? I found C# little easier than MATLAB for GUI application. please help

10 件のコメント

Adam
Adam 2017 年 8 月 7 日
Speed is not generally much of an issue in the GUI aspect of an application, more what you actually do 'under the hood'. Which aspect of the GUI are you concerned about being slow? Usually user-response time is not so fast as to make GUI-specific commands very time-sensitive, but it depends what you are looking to do.
Stephen23
Stephen23 2017 年 8 月 7 日
編集済み: Stephen23 2017 年 8 月 7 日
" I need a sincere suggestion, do I shift to C# for GUI application? "
How are we supposed to know? You explained nothing about what your code does, what bottlenecks it has, or how you tested it.
Do you have experience writing efficient MATLAB code? If you show us the code or give a much more detailed explanation then we might be able to help you.
Sairah
Sairah 2017 年 8 月 7 日
編集済み: Sairah 2017 年 8 月 8 日
@Stephen Basically I am developing the GUI for tracking objects at real time. I received data from the sensor networks and estimates the position, computing the object distances (from the global reference point) and statistical analysis simultaneously. I am facing the trouble when more than 3 objects encountered and CAD file of map image I called, makes the GUI performance slow Actually I am new in developing GUI and have to decide the appropriate platform for my application ASAP. As I came across several MATLAB GUIs but not as realtime application.
Sairah
Sairah 2017 年 8 月 7 日
Adam Thanks for your reply But I feel the slow speed situation. When I called the image CAD file and plotting data in real time the processing speed becomes slow.
Adam
Adam 2017 年 8 月 7 日
How are you plotting the data? Repeated calls to plot will be slow. If you are updating the same plot with new real time data then you should always keep a handle to the original plotted line and update its XData and YData properties (and any others that may need changing) so that you only have one call to the plot function.
There are a lot of code optimisations possible in any language, but it depends entirely on your code and what the profiler says is the bottleneck.
If the bottleneck literally Matlab plotting instructions that are already optimally handled with as few calls to the expensive functions as possible then you may be at the limit of speed, but otherwise there could be huge improvements.
e.g. someone posted code recently that was slow because it was running a loop a few million times. Within the loop they were accessing an edit box and calling str2double on its contents. This resulted in 14 million calls to this function when it could just be taken out of the loop and called once. This speeded up the result a lot.
doc profile
will help you work out where your bottlenecks are, but be careful how you use it and interpret it for a GUI - make sure that you aren't looking at idle time counted in certain functions while it is actually waiting for user input.
Jan
Jan 2017 年 8 月 7 日
@Sairah: "called the image CAD file" might be a problem, but it is not clear, what this means exactly. Real-time processing and the slow hard disk access are not matching well together.
Sairah
Sairah 2017 年 8 月 8 日
@Adam my code will also run in an infinite loop, And yes I will use plot commands as wells as the "if and switch statements" usage is a lot because the data reception is from the whole building, and the persons are considered as objects which are to be tracked. actually, I didn't write the complete code yet I wrote each block separately, to check the functionality
Sairah
Sairah 2017 年 8 月 8 日
編集済み: Sairah 2017 年 8 月 8 日
@Jan Simson thank you for your comments, actually, I am not calling the CAD file directly first I convert it into image file and read it in my program, using "imread(image) and imshow(image)" commands
Walter Roberson
Walter Roberson 2017 年 8 月 8 日
Is the CAD file being generated over and over again by an external program? Are you making calls to an external program asking it to generate a new version of the CAD file?
Is there a reason you are not using a constant CAD image (with no people on it) and then drawing the people on top of that in MATLAB ?
Sairah
Sairah 2017 年 8 月 8 日
編集済み: Sairah 2017 年 8 月 9 日
yes @Walter Roberson I just use image file (generated by AutoCAD)this image file is a Map of the building and then I plot the moving objects on that image file.

サインインしてコメントする。

回答 (3 件)

Jan
Jan 2017 年 8 月 7 日

1 投票

Of course Matlab gets slow during the execution if it has a lot do to. This may be the nature of the problem, e.g. if huge data sizes have to be processedm or a problem of the programming, e.g. for iteratively growing arrays, creation of a large number of graphic objects (instead of updateing the XData, YData, ZData of existing objects).
Matlab's graphics output is not fast. If the job requires e.g. the rendering of complex 3D objects, other programming languages migth be faster. Without knowing any details about the actual problem, it is impossible to draw a reliable conclusion.
Sairah
Sairah 2017 年 8 月 8 日
編集済み: per isakson 2017 年 8 月 8 日

0 投票

Here I am sharing one of my code block in which I use two push buttons, 1st push button reads the image file and the 2nd push button is reading a text file which contains x and y positions of the object and plots the x and y positions on an image.
(Before commenting on this let me tell you guys one thing that I have intermediate programming skill and I am new to MATLAB GUI as well.)
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
A = imread('HCRC MAP.jpg');
B = imrotate (A,90);
imshow(B);
hold on;
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
tag = [];
fid = fopen('D:\work\MATLAB GUI Programs\GUI_Testing_file.txt');
while ~feof(fid)
line = fgetl(fid);
nums = str2num(line);
tag = [(nums(1)*100); (nums(2)*100)];
plot(620+tag(1),2196-tag(2),'b.', 'LineWidth', 0.1);%90 rotate
hold on
pause(0.001)
end
fclose(fid)
Sairah
Sairah 2017 年 8 月 8 日
編集済み: Sairah 2017 年 8 月 8 日

0 投票

And in another part of the code is using push buttons and one check box.
% --- Executes on button press in start_reception.
function start_reception_Callback(hObject, eventdata, handles)
global flag
flag = 0;
fid = fopen( 'D:\work\MATLAB GUI Programs\GUI_Testing_file2.txt');
while ~feof(fid)
line = (fgetl(fid));
data = str2num(line);
Tag1 = [data(2); data(3)];
Tag2 = [data(5); data(6)];
pause(0.01)
if flag == 0
hold off
plot(Tag1(1), Tag1(2),'rd', Tag2(1), Tag2(2),'bd','MarkerSize',8)
elseif flag == 1
hold on
plot(Tag1(1), Tag1(2),'r.',Tag2(1), Tag2(2),'b.','LineWidth',0.2)
hold off;
elseif flag ==2
flag = 0;
elseif flag == 3
break
end
h = rectangle('Position',[0.45,0.45,(3.60-0.45),(4.50-0.45)],'Curvature',[0.45,0.45],'LineWidth',2,'LineStyle','--');%nominal path
hold on;
axis([0 4 0 5])
end
fclose(fid)
% --- Executes on button press in Track_Tag1.
function Track_Tag1_Callback(hObject, eventdata, handles)
% hObject handle to Track_Tag1 (see GCBO)
global flag
if get(handles.Track_Tag1,'Value') == get(hObject,'Max')
flag = 1
else
flag =2
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
if get(hObject,'Value') == get(hObject,'Max')
flag = 3
else
flag = 0
end

3 件のコメント

per isakson
per isakson 2017 年 8 月 8 日
編集済み: per isakson 2017 年 8 月 8 日
Creating graphic objects is expensive. Thus, plot(...) inside a loop is slow. It's faster to keep the objects and change their property values.
Sairah
Sairah 2017 年 8 月 8 日
@ per Isakson, what do you mean "It's faster to keep the objects and change their property values?
Stephen23
Stephen23 2017 年 8 月 9 日
編集済み: Stephen23 2017 年 8 月 9 日
@Sairah: MATLAB graphics is based on Objects. The MATLAB documentation explains this clearly:
In practice, per isakson's suggestion means, for example, creating a line just once and thereafter simply changing its properties (e.g. the X and Y data). All useful graphics functions return handles to some object, and the documentation clearly states what kind of object and has a link to that object's properties. So the best thing you could do for your self is start reading the MATLAB documentation and trying the examples.
And did I mention: read the documentation! The more you use it, the easier it will be to find the right information in it.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange그래픽스 객체 식별 についてさらに検索

タグ

質問済み:

2017 年 8 月 7 日

編集済み:

2017 年 8 月 9 日

Community Treasure Hunt

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

Start Hunting!