arrange repeated elements in an array then find a 95% confidence interval
1 view (last 30 days)
Show older comments
Hello, i have the following data,
category value1 value2
1 20 5
2 25 7
3 18 2
4 27 9
1 21 6
2 26 8
3 17 1
4 25 11
1 23 4
2 27 5
3 16 2
4 26 8
i want to do the following: first i want to summarize them in an array such that (value1 and value 2 not necessarily in the same array)
category value1 value2
1 20 21 23 5 6 4
2 25 26 27 7 8 5
3 18 17 16 2 1 2
4 27 25 26 9 11 8
then i want to find the 95th% for each category and plot it as a continuous line for all categories such as the following graph, if i can get the graph without doing the first step that's also be great. here the graph is only for value1
0 Comments
Answers (1)
Guru Mohanty
on 12 Mar 2020
Hi, I understand you are getting issues in categorizing and plotting some sample data. You may use find function to get the index for all the categories and plot using plot function. Here is a sample code for it.
clc;
clear all;
% Categories Value1 Value2
A= [1 20 5;
2 25 7;
3 18 2;
4 27 9;
1 21 6;
2 26 8;
3 17 1;
4 25 11;
1 23 4;
2 27 5;
3 16 2;
4 26 8;];
max_cat= max(A,[],1);
for i=1:max_cat(1)
Val(:,i)=find(A(:,1)==i);
cat_value1(:,i)=A(Val(:,i),2); % for value 1
cat_value2(:,i)=A(Val(:,i),3); % for value 2
end
%Getting 95% of data
cat_value1_ll=0.95*cat_value1;
cat_value1_ul=1.05*cat_value1;
%Plotting for Category1 Value 1
plot(cat_value1(1,:));
hold on;
plot(cat_value1_ll(1,:),'.-');
plot(cat_value1_ul(1,:),'.-');
hold off;
0 Comments
See Also
Categories
Find more on Descriptive Statistics and Visualization 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!