How to put different viewing angle of 3d plot in GUI
Show older comments
Hello,
I haven't found this question anywhere similar Im having this problem that i can't put different viewing angle on push button in GUI (graphical user interface). When i only put for example view(90,0) it works but on push button i have tried to create plot3 again.. what i haven't tried and still nothing.
Ill try to post my code here. Also its a bit complicated because i am opening folders which each of them includes 15 files with different data. But i think there should be some kind of solution.
Heres the code:
%% File Reading for test = 1:2 color_plot = ['r' 'g' 'y']; EntireMeasurement = {}; %Array for all measurements ArrayOfMeasurement={}; %Array for one measurement result repeat = true; %initializing counter values valuescount = 1; myFolder = 'D:\Failas\Nauji matavimai';
if ~isdir(myFolder)
errorMessage = sprintf('Warning: The following folder does not exist:\n%s defaulting folder to C:, change myFolder variable to avoid this warning', myFolder);
warndlg(errorMessage);
myFolder = 'C:\'
return;
end
foldername = uigetdir(myFolder, 'Select Results folder');
currentDirectory = foldername
[upperPath, deepestFolder, ~] = fileparts(currentDirectory)
filePattern = fullfile(foldername, './*.csv');%, 'MultiSelect','on');
csvFiles = dir(filePattern);
repeat = 0;
while repeat < length(csvFiles)
fileNamePattern_s = 'Height %fm Distance %fm';
distDimensions = sscanf(csvFiles(repeat+1).name, fileNamePattern_s);
height = distDimensions(1);
distance = distDimensions(2);
baseFileName = csvFiles(repeat+1).name;
fullFileName = fullfile(foldername, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
fid = fopen(fullFileName,'r');
%% Group read values into arrays
Receiver = []; %Receiver address array
Transmitter = []; %Transmitter address array
RSSI = []; %RSSI address array
Time = []; %Time address array
while ~feof(fid)
line=fgets(fid); % Gets one line and sends it to check
[Receivertmp, Transmittertmp, RSSItmp, Timetmp]=strread(line(1:length(line-2)),'%s%s%d%s', 1, 'delimiter', ';'); %delimiter shows where the word is going to end in this case at ';'
Receiver = [Receiver Receivertmp]; %Adds one element at the time while 'while' is working
Transmitter = [Transmitter Transmittertmp];
RSSI = [RSSI RSSItmp];
Time = [Time Timetmp];
end
Records = struct('Receiver',[Receiver], 'Transmitter', [Transmitter], 'RSSI', [], 'Time', [Time]); %Structure which holds a record of each value
for i=1:length(RSSI)
Records(i).RSSI=RSSI(i); %Put every value for every record
end
%% Compare and group similar values
Unikal = unique({Records.Receiver}); %Select unique names from Records.Receiver changing it to cell array with '{}' A={}; % Creaty an empty cell array
for i=1:length(Unikal) %Go through every unique address
A(i) = {Records(strcmp(Unikal(i), {Records.Receiver}))}; %strcmp compare an unique Records with all records and we get logic matrix which we use to index elements of the records
end
B=cell2mat(A(strcmp(Unikal, '001830EDD5DF'))); %cell array convert to simple matrix. According to this we take whatever values we need
%B is a structure, elements B.RSSI(14), B.Receiver(17)
%If we need all the values A= [B.RSSI]
%figure
for i = 1:length(B)
x(i) = {B(i).Time(13:21)};
end
%set(gca, 'XTick',1:length(x'), 'XTickLabel',{x'}); %56 change to length()
% xticklabel_rotate(1:length(x),90,x,'interpreter','none');
ArrayOfMeasurement(1)={[B.RSSI]}; %RSSI saves as value in results array
fclose(fid);
ArrayOfMeasurement(2)={distance};
ArrayOfMeasurement(3)={height};%enters distance in the same calculated results array
EntireMeasurement{valuescount} = ArrayOfMeasurement; %puts single tests results into global cell array's single cell.
valuescount=valuescount + 1;
ArrayOfMeasurement(:) = {[]};
repeat = repeat +1;
end
DistanceTestNumber = length(EntireMeasurement); %number of distance values
for y=1:DistanceTestNumber
Tempcell = EntireMeasurement{y}; %select single measurements cell y
tempstd = std([Tempcell{1:end -1}]); % get standart deviation of RSSI values from 1 to end-1-st log file, end element is distance.
tempmean = mean([Tempcell{1:end-1}]); % get mean of RSSI values from 1 to end-1-st log file, end element is distance.
Tempcell{end + 1} = tempstd; %set end +1 element (new element at the end) as standart deviation
Tempcell{end + 1} = tempmean; %set end +1 element (new element at the end) as mean
EntireMeasurement{y} = Tempcell; %Overwriting old cell
end %Basic premise of this loop is to take cell with data and distance and add both mean and standart deviation
for i= 1:DistanceTestNumber
Tempcell = EntireMeasurement{i};
distd(test,i)= Tempcell{end-3}; %susidedam atskirai i masyvus ir nuplotinam ant galo
disth(test,i) = Tempcell{end -2}; %{end -2} is height
stdevs(test,i) = Tempcell{end-1};
aver(test,i) = Tempcell{end};
end
subplot(1,2,test);
xlim([0 5]);
ylim([0 2]);
zlim([-80 -50]);
plot3_errorbars_surf(distd(test, :), disth(test, :), aver(test, :), stdevs(test, :));
% view(90,0), shading interp
if test==1
title(deepestFolder,'FontSize',12);
else
title(deepestFolder,'FontSize',12);
end
xlabel ('Distance, m','FontSize',12);
ylabel ('Height, m','FontSize',12);
zlabel ('RSSI, dB','FontSize',12);
grid on;
% Choose default command line output for simple_gui
handles.output = hObject;
end
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes simple_gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = simple_gui_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on selection change in plot_popup.
function plot_popup_Callback(hObject, eventdata, handles)
% hObject handle to plot_popup (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns plot_popup contents as cell array
% contents{get(hObject,'Value')} returns selected item from plot_popup
% --- Executes during object creation, after setting all properties.
function plot_popup_CreateFcn(hObject, eventdata, handles)
% hObject handle to plot_popup (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in surf_pushbutton.
function view_pushbutton_Callback (hObject, eventdata, handles)
% hObject handle to surf_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Display surf plot of the currently selected data
% --- Executes on button press in mesh_pushbutton.
function mesh_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to mesh_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Display mesh plot of the currently selected data
mesh(handles.current_data)
% --- Executes on button press in contour_pushbutton.
function contour_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to contour_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Display contour plot of the currently selected data
contour(handles.current_data)
Any help here?
Answers (0)
Categories
Find more on Graphics Performance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!