How to assign symbols to the data in Matlab - matlab

I am trying to plot some data with categories. However, I couldn't manage to plot my data according to the categories and show a legend for them. Therefore, I am asking a little bit help to this issue.
Example data;
Name
Brand
Mt
Enes
Renault
2.6
Avni
Tofaş
2.38
Asaf
Tofaş
3.06
My experience, I have managed to plot these data with two plot command overlaying each other grouping them by Brand. However, this time, one group of data has 2 line (as Tofaş has two data) and the other has only one line data (as in Renault). Thus, x-axis is confusing and not giving a healty graph.
The other issue with this, I can't label the x-axis according to Name when I plot two graph overlaying.
figure
plot(table.Mt, 'o');
xtickangle(90)
sizes = size(table.Name);
a1 = gca;
a1.XTick = [1:sizes];
a1.XTickLabel = table.Name;
the output of the code above
[Ism, Ind] =ismember(table.Brand, 'Tofaş');
plot(Ism, 'o')
the output of second code block above
As you can see, when I select only spesific Brand. The rest of arrray filling with zero (0) which I don't want to.
What I want is that plotting all data with spesific symbols for each Brand together.
Thank you
Enes

Related

Retrieve Gradient of Reference Line Generated by probplot

I am generating probability plots for a number of data sets in matlab.
I am plotting them using probplot with a weibull distribution reference line
data = [1,1,1,1,2,2,2,3,4,5,3,3,2,2,1,3,5,7,2,4,2] ;
h = probplot('weibull',data) ;
This function as per the matlab documentation returns a graphic array object. This appears to only contain the original data and not the reference line.
Is there any way of retreiving information about about this reference line without plotting it and indiviually extracting it using the figure tools (very much not an option I'd like to go down as there are potentionally hundreds of plots to go through).
I can see there is wblplot that returns a line array of 3 lines, one of which is the original data and one of the others is likely the reference the line however I will have to try different distributions to fit further down the road and would prefer to keep a generic approach.
You are wrong!
data = [1,1,1,1,2,2,2,3,4,5,3,3,2,2,1,3,5,7,2,4,2] ;
h = probplot('weibull',data) ;
b=h(2);
figure
plot(b.XData,b.YData)
h is a graphic array object, so its an array. The first element contains the original data, but the second h(2) contains the reference line.

MATLAB loading data from multiple .mat files

My data is x,y co-ordinates in multiple files
a=dir('*.mat')
b={a(:).name}
to load the filenames in a cell array
How do I use a loop to sequentially load one column of data from each file into consecutive rows of a new/separate array......?
I've been doing it individually using e.g.
Load(example1.mat)
A(:,1)=AB(:,1)
Load(example2.mat)
A(:,2)=AB(:,1)
Load(example3.mat)
A(:,3)=AB(:,1)
Obviously very primitive and time consuming!!
My Matlab skills are weak so any advice gratefully received
Cheers
Many thanks again, I'm still figuring out how to read the code but I used it like this;
a=dir('*.mat');
b={a(:).name};
test1=zeros(numel(b),1765);
for k=1:numel(b) S=load(b{k});
I then used the following code to create a PCA cluster plot
test1(k,:)=S.AB(:,2); end [wcoeff,score,latent,tsquared,explained] = pca(test1,... 'VariableWeights','variance');
c3 = wcoeff(:,1:3) coefforth = inv(diag(std(test1)))*wcoeff; I = c3'*c3 cscores = zscore(test1)*coefforth;
figure() plot(score(:,1),score(:,2),'+') xlabel('1st Principal Component') ylabel('2nd Principal Component') –
I was using 'gname' to label the points on the cluster plot but found that the point were simply labelled from 1 to the number of rows in the array.....I was going to ask you about this but I found out simply through trial and error if I used 'gname(b)' this labels the points with the .names listed in b.....
However the clusterplot starts to look very busy/messy once I have labelled quite a few points so now I am wondering is is possible to extract the filenames into a list by dragging round or selecting a few points, I think it is possible as I have read a few related topics.....but any tips/advice around gname or labelled/extracting labels from clusterplots would be greatly appreciated. Apologies again for my formatting I'm still getting used to this website!!!
Here is a way to do it. Hopefully I got what you wanted correctly :)
The code is commented but please ask any questions if something is unclear.
a=dir('*.mat');
b={a(:).name};
%// Initialize the output array. Here SomeNumber depends on the size of your data in AB.
A = zeros(numel(b),SomeNumber);
%// Loop through each 'example.mat' file
for k = 1:numel(b)
%// ===========
%// Here you could do either of the following:
1)
%// Create a name to load with sprintf. It does not require a or b.
NameToLoad = sprintf('example%i.mat',k);
%// Load the data
S = load(NameToLoad);
2)
%// Load directly from b:
S = load(b{k});
%// ===========
%// Now S is a structure containing every variable from the exampleX.mat file.
%// You can access the data using dot notation.
%// Store the data into rows of A
A(k,:) = S.AB(:,1);
end
Hope that is what you meant!

MATLAB Box Plot for large groups of Measurements

I've got basically three large groups of measurements and im trying to generate a BoxPlot with 4 Boxes. One box for each group and the last one for all groups joined.
I've tried with this code
A = rand(1417725,1)
B = rand(2236508,1)
C = rand(3100641,1)
D = [A;B;C]
X= [A;B;C;D]
group = [repmat({'a'},1417725,1); repmat({'b'},2236508,1); repmat({'c'},3100641,1); repmat({'d'},6754874,1)];
boxplot(X,group)
but at the end i get " Out of memory" and i can't get the plot.
do you have any idea to solve this problem??
Thank you!
Instead of creating a huge (in terms of memory) cell array of strings, create a much smaller array of for instance int8 integers:
group = [ones(size(A),'int8');2*ones(size(B),'int8');3*ones(size(C),'int8');4*ones(size(D),'int8')];
Then, after plotting, change the labels in the plot to the desired names:
set(gca, 'XTick', 1:4, 'XTickLabel', {'a','b','c','d'});
Maybe you have enough memory to do it this way..

Plotting multiple time series using VPlotContainers in Chaco. Limit to the number of VPlotContainer objects you can use

I wish to plot multiple time series data stored in a NumPy array, in the same plot but with each time series offset, so effectively it has it's own Y axis. I figured the best way to do this may be to put each series in a separate VPlotContainer, but when I call the configure_traits() call I am just getting a blank window. Is the issue that I have too many time series for the machinery to handle?
class EEGPlot(HasTraits):
plot = Instance(VPlotContainer)
traits_view = View(
Item('plot',editor=ComponentEditor(), show_label=False),
width=1024, height=768, resizable=True, title="EEG Preview")
def __init__(self, eegObject):
super(EEGPlot, self).__init__()
x = xrange(eegObject.windowStart, eegObject.windowEnd)
plotNames = {}
allPlots = []
for idx, column in enumerate(eegObject.data[:,:].transpose()): # only included indexes to indicate array dimensions
y = column
plotdata = ArrayPlotData(x=x, y=y)
myplot = Plot(plotdata)
myplot.plot(("x", "y"), type="line", color="blue")
plotNames["plot{0}".format(idx)] = myplot
allPlots.append(plotNames["plot{0}".format(idx)])
container = VPlotContainer(*allPlots)
container.spacing = 0
self.plot = container
So my EEGObject is a NumPy array with 2 dimensions. Around 1500(row) by 65(col). I am wondering if I getting the blank screen because I am doing something wrong or if I am just giving it too many containers?
The answer appears to be that I was using the wrong tools to try and achieve what I needed. VPlotContainers are for separating distinct plots (most likely from different data sources even) within a main display container.
When I fed a test array into the code in the original question that only had 5 columns, then each column plotted in a separate container, but when I increased the columns to above 6 then the UI window would appear blank.
So I guess the answer is that yes, there would appear to be a limit to the number of VPlotContainers you can use, but I don't know if this limit is absoloute or bound by the space dedicated to the main UI window or what.
Either way, using VPlotContainers is not an appropriate technique to display multiple time series data. The correct object would be a MultiLinePlot if you wish the lines to be separated, or an OverlayPlotContainer.
http://docs.enthought.com/chaco/user_manual/plot_types.html#multi-line-plot
I am also having issues using MultiLinePlot, but have moved this question to a separate thread here:
Chaco MultiLinePlot - unable to get simple plot to display, wondering if package broken?

MATLAB query about for loop, reading in data and plotting

I am a complete novice at using matlab and am trying to work out if there is a way of optimising my code. Essentially I have data from model outputs and I need to plot them using matlab. In addition I have reference data (with 95% confidence intervals) which I plot on the same graph to get a visual idea on how close the model outputs and reference data is.
In terms of the model outputs I have several thousand files (number sequentially) which I open in a loop and plot. The problem/question I have is whether I can preprocess the data and then plot later - to save time. The issue I seem to be having when I try this is that I have a legend which either does not appear or is inaccurate.
My code (apolgies if it not elegant):
fn= xlsread(['tbobserved' '.xls']);
time= fn(:,1);
totalreference=fn(:,4);
totalreferencelowerci=fn(:,6);
totalreferenceupperci=fn(:,7);
figure
plot(time,totalrefrence,'-', time, totalreferencelowerci,'--', time, totalreferenceupperci,'--');
xlabel('Year');
ylabel('Reference incidence per 100,000 population');
title ('Total');
clickableLegend('Observed reference data', 'Totalreferencelowerci', 'Totalreferenceupperci','Location','BestOutside');
xlim([1910 1970]);
hold on
start_sim=10000;
end_sim=10005;
h = zeros (1,1000);
for i=start_sim:end_sim %is there any way of doing this earlier to save time?
a=int2str(i);
incidenceFile =strcat('result_', 'Sim', '_', a, 'I_byCal_total.xls');
est_tot=importdata(incidenceFile, '\t', 1);
cal_tot=est_tot.data;
magnitude=1;
t1=cal_tot(:,1)+1750;
totalmodel=cal_tot(:,3)+cal_tot(:,5);
h(a)=plot(t1,totalmodel);
xlim([1910 1970]);
ylim([0 500]);
hold all
clickableLegend(h(a),a,'Location','BestOutside')
end
Essentially I was hoping to have a way of reading in the data and then plot later - ie. optimise the code.
I hope you might be able to help.
Thanks.
mp
Regarding your issue concerning
I have a legend which either does not
appear or is inaccurate.
have a look at the following extracts from your code.
...
h = zeros (1,1000);
...
a=int2str(i);
...
h(a)=plot(t1,totalmodel);
...
You are using a character array as index. Instead of h(a) you should use h(i). MATLAB seems to cast the character array a to double as shown in the following example with a = 10;.
>> double(int2str(10))
ans = 49 48
Instead of h(10) the plot handle will be assigned to h([49 48]) which is not your intention.