using app designer create app that can read and load 100 excel file then use next button to observe graph
2 ビュー (過去 30 日間)
古いコメントを表示
after loading and plotting graph
then use slider to run point on graph and value shows on edit field use that editfield number for new plot on another app
i have matlab script which load the readtable and load excel file and plot files then save them as picture creates new excell file with output of new graph
if anyone can help me with how to approuch it or guild me on how can i use next button to load new file automaticly after pressing the next buttom and tel me how can i use tell the appdesigner to use 100 data one by one and use neccessry data for all common in my mlapp tamplet instead of copy pasting load function for each common
here my scrip
numxlfile =length(1:1:98);
%% calling the excel file and saving them
Folderlocation = '--';
data=cell([1,numxlfile]);
for k= 1:numxlfile %starts the loop
%define your filename according to the file index
filename=sprintf(['RawData_',num2str(k),'.csv']);
data{k}= readtable(filename); %load file
end %ends the loop
for n = 1 :length(data)
cellcontents =data{n} ;
array=cellcontents(:,:);
%array =array2table(cellcontents(10:end,:),'VariableNames',colmnam) ;
fnm = sprintf('Raw_%d.mat',n);
save(fnm,'array');
% h = findobj('type','figure')
% inputarray(1 : length(h)) = input('Input value for offset yield strength from observation:')
end
%% creating/saving and plotting the true data
rng('default') % for reproducibility
% Pre-allocate loop vars
truev_str = zeros(numxlfile,1);
truev_stress= zeros(numxlfile,1);
% newgraphdata = zeros(length(Tenstress),1);
peakvalue = zeros(numxlfile,1);
peak_strian = zeros(numxlfile,1);
newgraphdata = [];
z=1
for i = 1:numxlfile
ii = i+50;
file = load(fullfile('C:\Users\sghandal\Downloads\RE__Re__ (1)\recreat data', ...
sprintf('Rawdata_%d.mat',ii)));
Tenstress = array2table(file.array.TensileStress);
strainone = array2table(file.array.Strain1);
engg_ = file.array.Extension;
engg_exten=array2table(engg_(:,1)*(16^-1));
%% finding the index for given strain value
% figure (ii);
% hold on
% plot(strainone{:,1},Tenstress{:,1},engg_exten{:,1},Tenstress{:,1})
% % set(gca, 'XTick',1:length(strainone{:,1}), 'FontSize',7)
% % xticklabels (strainone{:,1})
% grid on
% hold on
% m=1;
[~,index] = ismembertol(0.0152,strainone{:,1}, 'ByRows', true, ...
'OutputAllIndices', true, 'DataScale', 1);
row =index(1,1);
if row{1,1} == 0
int = input('enter value base on the ')
[~,index] = ismembertol(int,strainone{:,1}, 'ByRows', true, ...
'OutputAllIndices', true, 'DataScale', 1);
row = index;
if row{1,1} == 0
int = max(findpeaks(engg_exten{:,1}))
[~,index] = ismembertol(int(end),strainone{:,1}, 'ByRows', true, ...
'OutputAllIndices', true, 'DataScale', 1);
if row{1,1} == 0
[~,x]= findpeaks(strainone{:,1});
t = accumarray(x,1);
ke = 0.01<= t <=0.05;
o1 = [strainone{:,1}(ke)];
Aid = ismembertol(strainone{:,1},o1(:,1));
Anewid = strainone{:,1}.* Aid;
AAA = Anewid(islocalmax(Anewid));
[~,index] = ismembertol(max(AAA),strainone{:,1}, 'ByRows', true, ...
'OutputAllIndices', true, 'DataScale', 1);
row = index
if row{1,1} == 0
[~,x]= findpeaks(strainone{:,1});
t = accumarray(x,1);
ke = t >0.05;
o1 = [strainone{:,1}(ke)];
Aid = ismembertol(strainone{:,1},o1(:,1));
Anewid = strainone{:,1}.* Aid;
AAA = Anewid(islocalmin(Anewid));
[~,index] = ismembertol(max(AAA),strainone{:,1}, 'ByRows', true, ...
'OutputAllIndices', true, 'DataScale', 1);
row = index
if row{1,1} == 0
[~,x]= findpeaks(strainone{:,1});
t = accumarray(x,1);
ke = t >0.07;
o1 = [strainone{:,1}(ke)];
Aid = ismembertol(strainone{:,1},o1(:,1));
Anewid = strainone{:,1}.* Aid;
AAA = Anewid(islocalmin(Anewid));
[~,index] = ismembertol(max(AAA),strainone{:,1}, 'ByRows', true, ...
'OutputAllIndices', true, 'DataScale', 1);
if row{1,1} == 0
vv =[0.01501 0.0275 0.0207 0.0229 0.030 0.0440 0.01948 0.011 0.03416...
0.0140 0.02]
[~,index] = ismembertol(any(vv),strainone{:,1}, 'ByRows', true, ...
'OutputAllIndices', true, 'DataScale', 1);
row = index;
if row{1,1} == 0
int = input('enter value base on the ')
[~,index] = ismembertol(int,strainone{:,1}, 'ByRows', true, ...
'OutputAllIndices', true, 'DataScale', 1);
row = index;
else row{1,1} == 0
limit = 1e-3;
abs(strainone(1:end) - 0.02) < limit;
index = m;
intervalue(R) = input('enter value base on the ')
[~,index] = ismembertol(intervalue,strainone{:,1}, 'ByRows', true, ...
'OutputAllIndices', true, 'DataScale', 1);
row =index;
m=m+1;
end
end
end
end
end
end
end
row = [row{1,1}(1,1)];
%% new graph data
bottomhalf=array2table((((file.array.Extension(row:end)- file.array.Extension(row,1))./16)+ ...
file.array.Strain1(row,1)));
bottomtop = array2table(file.array.Strain1(1:row-1));
% combinding found data
newstressval =[bottomtop;bottomhalf];
[Au,~,ix] = unique(bottomhalf{:,1},'stable');
tally = accumarray(ix,1);
keep = 2< tally <4;
out1 = [Au(keep), tally(keep)];
Ai = ismember(bottomhalf{:,1},out1(:,1));
Anew = bottomhalf{:,1}.* Ai;
AA = Anew(islocalmin(Anew));
% finding Elongation
newval = table2array(newstressval);
a= newstressval.Var1(end,end);
bb =max(file.array.Strain1(1:row-1))
[~,ind] = ismembertol(AA(end),bottomhalf{:,1}, 'ByRows', true, ...
'OutputAllIndices', true, 'DataScale', 1);
r = [ind{1,1}(end,1)];
truev_str(i,:)=AA(end);
endtruev =table2array(Tenstress);
truev_stress(i,:)= endtruev(r,1);
% finding peak
peakvalue(i,:) = table2array(array2table(max(findpeaks(Tenstress{:,1}))));
[~,idxs] = ismembertol(peakvalue(i,:),Tenstress{:,1}, 'ByRows', true, ...
'OutputAllIndices', true, 'DataScale', 1);
peak_strian(i,:) = newval(idxs{1,1})
L = length(newstressval.Var1);
%% saving graph data
[newgraphdata] = zeros(L,1);
k= k+1
for k = 1:1:98
if k == 1
newgraphdata(:,1) = newval;
Tg = table (newgraphdata,'VariableNames',{'true data'})
Graphdata = table2array(Tg)
save(['graphdata_' num2str(ii) '.mat'])
fgraph = 'Graphdatanew.xlsx';
writetable(Tg,fgraph,'sheet',num2str(ii));
continue
end
end
%% plotting
figure(ii);
pause(1)
hold all
p1 = plot(strainone{:,1},Tenstress{:,1},'--g');
p2 = plot (engg_exten{:,1},Tenstress{:,1},'b--');
p3 = plot(newstressval{:,1},Tenstress{:,1},'k','LineWidth',2);
xlim auto
grid on
title('Specimen strain stree curve # ',num2str(ii))
xlabel('strian \epsilon')
ylabel('stress \sigma (MPa)')
legend([p1,p2,p3],{'strain one','extension strian','true strian'},'Location','best')
xticklabels('auto')
fig_data = strcat('FIG_',num2str(i),'_',num2str(ii));
print(figure(ii),fig_data,'-dpng','-r400');
% pause(1)
z=z+1;
%% creating output data excel file
sheet =z;
T = table(truev_str,peakvalue,peak_strian,'VariableNames',{'strain','peak value','tensile strian'})
fname = 'finaldata.xlsx';
end
writetable(T,fname,'Sheet',1,'Range','A1')
0 件のコメント
回答 (1 件)
Dinesh
2023 年 12 月 22 日
Hi Shaghayegh.
For your MATLAB application, after loading and plotting the initial graph, you can enhance interactivity by incorporating a slider. Attach the slider to your data points so that as it moves, it updates a specific point on your graph. Correspondingly, an editable field can display the value of the current data point, which can then be used for further plotting or calculations. To automate the process of loading new files, implement a "Next" button in your app. Upon each press, increment a file index to load the subsequent file from a predefined list or directory, update the necessary data arrays, and then refresh the plot with the new data.
To efficiently manage the sequential loading of data (like iterating through 100 data files), you can maintain a counter or index as part of your app's state (defined in properties). Increment this index each time the "Next" button is clicked and use it to reference the next file to be loaded. Instead of copy-pasting the load function, encapsulate it into a reusable function or method within your app, passing the file index or name as a parameter. This way, each click of the "Next" button calls this function, effectively loading and plotting the new data set. By structuring your app to modularly handle these tasks, you ensure a cleaner, more maintainable codebase and a smoother user experience.
The following are the links to the documentation for button, slider and properties in app designer:
0 件のコメント
参考
カテゴリ
Help Center および File 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!