problem in plot with conditions
Mostrar comentarios más antiguos
hi,
I have table with 2000 rows and 3 columns , each sum(row) either be 1 or 2 or 3
I want to map that as graph. where each row represents user , if sum(row) of uers was 3, then I can know that user is active in online community. I think if got such graph ,it will be important in my work, but if no. of rows is 2000 how the graph will be?
Let c1 is first_column , c2 is seond_column, c3 is third_column
i.e for each row:
if c1=1 , then plot (no_row,1,’*’, ‘color’,’b’)
if c2=1 , then plot (no_row,2,’*’, ‘color’,’b’)
if c3=1 , then plot (no_row,3,’*’, ‘color’,’b’)
if c1=1 and c2=1 then plot (no_row,1,’*’, ‘color’,’g’)
plot (no_row,2,’*’, ‘color’,’g’)
if c1=1 and c3=1 then plot (no_row,1,’*’, ‘color’,’g’)
plot (no_row,3,’*’, ‘color’,’g’)
if c1=2 and c3=1 then plot (no_row,1,'*’, ‘color’,’g’)
plot (no_row,3,’*’, ‘color’,’g’)
if c1=1 and c2=1 and c3=1 then plot (no_row,1,’*’, ‘color’,’r’)
plot (no_row,2,’*’, ‘color’,’r’)
plot (no_row,3,’*’, ‘color’,’r’)
thanks in advance
2 comentarios
Walter Roberson
el 29 de Abr. de 2013
With your tests arranged like that, if all three columns are 1, then the row would end up getting plotted in 'b', 'g', and 'r'. I don't think that was your intention ?
To check: (0,2,1) and (0,1,2) are also possible? Can any one column contain a 3 ?
huda nawaf
el 29 de Abr. de 2013
Editada: huda nawaf
el 29 de Abr. de 2013
Respuestas (1)
Walter Roberson
el 29 de Abr. de 2013
coltab = [1 1 1; %no activity
0 0 1; %one period
0 1 0; %two periods
1 0 0]; %three periods
logtab = YourTable > 0;
colidx = 1 + sum(logtab, 2);
rowview = repmat([1 2 3], size(logtab,1), 1) .* logtab;
rowview(~rowview) = NaN;
pointsize = 8;
scatter(1:size(rowview,1), rowview .', pointsize, coltab(colidx, :));
6 comentarios
huda nawaf
el 29 de Abr. de 2013
Walter Roberson
el 29 de Abr. de 2013
Yes, that is what the code does. coltab is a color table, with [0 0 1] being blue, [0 1 0] being green, [1 0 0] being red. sum of 0 gets the first entry, sum of 1 gets the second entry, sum of 2 gets the third entry, sum of 3 gets the fourth entry.
huda nawaf
el 29 de Abr. de 2013
Walter Roberson
el 29 de Abr. de 2013
I will have to think more about scatter.
You have indicated that individual entries in the table might be greater than 1. Using (YourTable > 0) constructs an array that is 0 where the original entry was 0, and 1 where the original entry was non-zero. You do not care what the value was for each entry for plotting purposes: you only care that it is nonzero.
huda nawaf
el 29 de Abr. de 2013
Walter Roberson
el 29 de Abr. de 2013
Your sample code had
if c1=2 and c3=1
Anyhow, if you do not need to calculate logtab then you can replace logtab with YourTable in the code that follows.
I understand about the scatter problem; I need to think more about the best way to fix it.
Categorías
Más información sobre Graphics Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!