how to solve this error index?
1 view (last 30 days)
Show older comments
i Have five files i have to plot 50 percentile plot column 3 data with respect to 120:0.1:150.5 in one single plot
Files = dir('*.csv');
Filesc = struct2cell(Files);
NrFiles = size(Filesc,2);
for k = 1:NrFiles
filename = Filesc{1,k};
T{k,:} = readtable(filename);
end
Final_T = cat(1,T{:});
i=reshape(Final_T.r,5,24)
i(:)'
size(i)
x=120:0.2:124.6;
size(x)
per=prctile(i,50) % i hv to take 50 percentile of column 3 data from all the files and plot against 120:0.1:120.5
figure
plot(x, per)
grid
xlabel('b')
ylabel('r')
i am not able to plot properly 50 percentile plot for column 3 data which is present in all data files wrt 120:0.1:124.6 in one single plot . i want all the files data in one plot
Answers (1)
Rahul
on 4 Sep 2024
Hi ramya,,
I understand that you’re trying to plot 50 percentile plots of 3rd column data of five .csv files, onto a single plot.
Given your current code snippet, you can generate 50-percentile plot vectors of column data from each file using ‘prctile’ function and then plot against the desired x-axis limits onto a single figure using ‘hold’ command, as shown below:
% Reshape final table to get column data vectors
Final_T=reshape(Final_T.r,24,5);
% Desired x-axis limits
xRange = 120:0.1:150.5;
percentiles = zeros(length(xRange), 5);
for i = 1:length(NrFiles)
% Extract the third column
column3Data = Final_T(:, i);
% Calculate the 50th percentile for the current dataset
percentiles(:, i) = prctile(column3Data, 50)
end
figure;
for i = 1:size(percentiles, 2)
% Plot individual column percentiles
plot(xRange, percentiles(:, i), 'DisplayName', ['File ', num2str(i)]);
hold on;
end
Here is the resultant figure with five 50-percentile plots, indicated using legends:
For more information regarding custom n-percentile plots of datasets, refer to the documentation link mentioned below:
0 Comments
See Also
Categories
Find more on Line Plots 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!