How do I select a file to open from folder rather than typing in the csv file name into the code?

조회 수: 3 (최근 30일)
Hello, I have the following code where I put in the filename of interest to plot the data into the code. It would much things much quicker and easier if, when I run the code, it opens a folder selection window and then I can select the file or files of interest. How do I open a folder and select a file or files for my plots? Thanks so much!
%Insert csv file name of interest
Pswpdata = readtable('csv_file.csv');
%Compute the max values by the groups of Frequency Variable
T1 = groupsummary(Pswpdata, 'Frequency', 'max');
%Find the indices of the variables to be added
names = Pswpdata.Properties.VariableNames;
str = {'Gain','PAE','PLRF_dBm'};
%Adding 1 to the indices as the output by groupsummary() has an extra
%column for groupcounts
idx = find(ismember(names, str)) + 1;
%Plot the corresponding values
scatter(T1,'Frequency',idx,'filled')
hold on
grid on
legend('Location', 'Best')
title('GT,PAE & Pout (dB)')

채택된 답변

Les Beckham
Les Beckham 2023년 10월 31일
편집: Les Beckham 2023년 10월 31일
Check the documentation on uigetfile which will return the filename and, if you use the two output version, the path to the file selected by the user from a file browser type dialog. For example:
[fn, fpath] = uigetfile;
Pswpdata = readtable(fullfile(fpath, fn));
  댓글 수: 6

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by