Build charts from Excel.
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi everyone, I have a problem. Basically I have to work on an Excel sheet with many values. I have to create 8 charts with 8 different data sets inside. The ranges that I have to use are equally spaced in every series of data and in every scatter plot that I have to create so I had thought of using a code with for loops that would allow me to automate this procedure. But I can't build it. Initially I thought of creating a macro on VBA. I attach a txt (test) with the macro that I created on VBA which however does not work. Each series of data is made up of 7 values (range from 2 to 9 then from 10 to 17 and so on up to 58-65) the one relating to the attachment is only the first of the 8 graphics that I have to build. The second scatter plot will consist of the same data series number as the first with the same names only that the ranges will be out of phase by 64 for example if in the first chart the ranges of the first data series is 2-9 in the second chart it will be 66 -73, the second series 74-81 and so on for the other series of this second graph up to 122-129. This procedure, as I said, must be automated for 8 different graphs each consisting of 8 data series, the data series of each graph have a step of 7 and from one graph to another of 64 up to the last series of the eighth chart whose range will be 506-513. I hope I was clear, for a person who has practice in these things I don't think it's something very complicated but unfortunately I can't. If someone could help me I would be infinitely grateful because it would greatly facilitate the work I have to do. Thank you.
I also attach the excel sheet on which I have to work.
The macro that I attack have many problems:
1. I have to enter the names of the data series by hand and this is very inconvenient since the series in all the graphs are called the same way. The series names are always in order: 2.5 kW, 5 kW, 7.5 kW, 10 kW, 12.5 kW, 15 kW, 17.5 kW, 20 kW.
2. Create an initial curve in the extra chart which calls "series1"
3. It doesn't always work, sometimes it creates as many data series as the columns of the excel file that I have attached previously.
But the index update criteria are correct
3 Commenti
Risposte (1)
Mohammad Sami
il 6 Gen 2020
You can use two for loops.
The outer for loop can iterate over the column C, and subset the data and create new figure.
The inner for loop can interate over column D in the subset of the data to plot line.
t = readtable('ScenarioA4-20km.xlsx');
uniq_col_c = unique(t.Pw_kW_);
for i = 1:length(uniq_col_c)
Pw_kW = uniq_col_c(i);
t_sub = t(t.Pw_kW_ == Pw_kW,:); % subset the data by C
figure; %create new figure
hold on;
uniq_col_d = unique(t_sub.Ppv_kW_);
for j = 1:length(uniq_col_d)
% plot lines for each Ppv_kW
Ppv_kW = uniq_col_d(j);
t_sub_sub = t_sub(t_sub.Ppv_kW_ == Ppv_kW,:); % subset the data again by D
plot(t_sub_sub.Pb_kWh_,t_sub_sub.PowerToBa,'DisplayName',num2str(Ppv_kW)); % plot e vs q
end
hold off;
end
4 Commenti
Mohammad Sami
il 8 Gen 2020
detectImportOptions was introduced in R2016b. Hence the error in R2016a.
For R2016a, you can directly specify the sheet as a name value pair in readtable function
'Sheet' — Worksheet to read1 (default) | positive integer indicating worksheet index | string containing worksheet name
Worksheet to read, specified as the comma-separated pair consisting of 'Sheet' and a positive integer indicating the worksheet index or a string containing the worksheet name. The worksheet name string cannot contain a colon (:). To determine the names of sheets in a spreadsheet file, use [status,sheets] = xlsfinfo(filename). For more information, see xlsfinfo.
Example: 'Sheet', 2
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!