How to use uiget dir loops and different excel file names functioning altogether?
1 view (last 30 days)
Show older comments
Hi, my excel files start at R3, R4, ...R32. I want to be able to select them using uiget multiple files and run a loop. I have the following way below but this one writes excel files. How can I change this to write mat files instead? How can I use the command: dir_struct = dir('*.xlsx'); % for i = 1:numel(dir_struct) number(i) = str2double(dir_struct(i).name(10:(10+numel(dir_struct(i).name)-16))); % get the number-string out of the filename and turn it into a number (I have fixed the format there) end [revised_numbers, order] = sort(number); for i = 1:numel(order) [.... ] = xlsread(dir_struct(order(i)).name, ...); ... rest of code end
to be applicable to the code below and to make it work?
prompt={'Jet Diameter, D (inches):','Radial distance, R (inches):','Moving Average time, Tav (sec)'}; name='Input for simulation'; defaultanswer={'8','3','0.050'}; %Change as required. N=60; %this will control the width of the inputdlg answer=inputdlg(prompt,name,[1 N],defaultanswer); D=str2double(answer{1}); R=str2double(answer{2}); Tav=str2double(answer{3});
% 16 CHANNEL SCANIVALVE DSA 3217 16 %Sampling Frequency of 16 Channel Scanivalve Data Acquisition System (Hz) Samp_Freq=500;
% Sampling period dt(in sec) dT=1/Samp_Freq;
% calculateg no. of samples to be averaged n=floor(Tav/dT)
% Vertical locations of all 16 Channel Scanivalve pressure taps %DSA 3217 16 (in inches) z=0.5:0.5:8;
%Normalized Height with respect D z_norm=z/D;
%Normalized Height with respect the maximum height z_norm_height=z/max(z);
%Normalized radial distances away from jet initiation R_D=R/D
%density of air in slugs/ft3 rho=0.002223;
%======================================================================================================================== LOOP 1: READING ALL EXISTING EXCEL FILES xlsread([FileName,'.xlsx']) AND WRITING NEW EXCEL FILES ([FileName,'_Vmean.xlsx'],V_mean(:,1:16))
%FUNCTION 1 for k=1:27 FileName=['R',num2str(k)]; [num txt numtxt]=xlsread([FileName,'.xlsx']);
%converting deltaP's to Pressures P_psf=num(:,2:17)*144;
%FUNCTION 2 %Calculating Velocities for i=1:16 for ii=1:10000 if P_psf(ii,i)<0 V_Raw(ii,i)=-(sqrt(abs(2*P_psf(ii, i))/rho)); else V_Raw(ii,i)=(sqrt(abs(2*P_psf(ii, i))/rho)); end end end
%Calcultaion of Average Velocity for im=1:16; V_mean(:,im)=movmean(V_Raw(:,im), n); end % saving the velocity files as excel sheets xlswrite([FileName,'_Vmean.xlsx'],V_mean(:,1:16)); end %============================================================= %----------------------------------------------------------- %LOOP 2: READING ALL NEW EXCEL FILES FROM LOOP 1 ([FileName,'_Vmean.xlsx'] AND WRITING NEW EXCEL FILES ([FileName,'_Vmax.xlsx'],max_max_Vmean)
%reading the saved velocity files for n=1:27 FileName=['R',num2str(k)]; [num txt numtxt]=xlsread([FileName,'_Vmean.xlsx']);
%calculating maximum velocities for conservative design(peak of peaks) max_Vmean=max(num(:,:));
%finding overall maximum for a given radial distance from DB max_max_Vmean=max(max_Vmean);
%saving this maximum value in excel sheet xlswrite([FileName,'_Vmax.xlsx'],max_max_Vmean) end %============================================================= %----------------------------------------------------------- %LOOP 3: READING ALL NEW EXCEL FILES FROM LOOP 1 ([FileName,'_Vmax.xlsx']
%finding where maximum velocity occurs along radial distance out=cell(27,1); for m=1:27 FileName=['R',num2str(m)]; [out{m} txt numtxt]=xlsread([FileName,'_Vmax.xlsx']); end [max,loc]=max([out{:}]); %============================================================= %----------------------------------------------------------- %LOOP 4: READING ALL NEW EXCEL FILES FROM LOOP 2 ([FileName,'_Vmean.xlsx']
%Inputting file where maximum velocity occurs for r=loc FileName=['R',num2str(r)]; [num txt numtxt]=xlsread([FileName,'_Vmean.xlsx']); end
%location of maximum in the file of maximum radial distance [row, col] = find(ismember(num,max)); %Vertical distance of Pressure taps Z_max=col/2;
%Normalized velocity V_norm_TH=num(:,col)/max;
%Input Timefrom sample number and frequency Samples=1:10000; Time=Samples/Samp_Freq; %============================================================= %-----------------------------------------------------------
% Time History plot plot(Time,V_norm_TH),xlabel('Time in sec'),ylabel('V/Vmax'), title('Time History at location having maximum velocity'); figure
%Vertical velocity profile V_norm_VP=num(row,:)/max; Z_norm=(0.5:0.5:8)/Z_max; plot(V_norm,Z_norm),xlabel('V/Vmax'),ylabel('Z/Zmax'), title('Vertical velocity profile at time having maximum velocity')
1 Comment
Jan
on 24 Sep 2018
Edited: Jan
on 24 Sep 2018
This is a lot of unreadable code. Please mark it with the mouse and press the "{} Code" button.
I guess all you want to do is to replace
for k=1:27
FileName=['R',num2str(k)];
by
dir_struct = dir('*.xlsx');
for i = 1:numel(dir_struct)
FileName = fullfile(dir_struct(i).folder, dir_struct(i).name)
But what does "uiget multiple files" mean? Perhaps:
[filename, pathname] = uigetfile('*.xlsx', 'MultiSelect', 'on');
for i = 1:numel(filename)
FileName = fullfile(pathname, filename{i})
Answers (0)
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!