MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by huda nawaf
on 29 Apr 2013

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

*No products are associated with this question.*

Answer by Walter Roberson
on 29 Apr 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, :));

Show 3 older comments

Walter Roberson
on 29 Apr 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
on 29 Apr 2013

I said that the entry in each cell impossible be greater than 1 . it is at most be 1. please go back to my comments

anyway, I have got this error: ??? Error using ==> scatter at 73

X and Y must be vectors of the same length.

error in ==> bar_plot_table_time at 49

scatter(1:size(rowview,1), rowview .', pointsize, coltab(colidx, :));

Walter Roberson
on 29 Apr 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.

## 2 Comments

## Walter Roberson

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/73962#comment_146116

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

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/73962#comment_146125

sorry ,I forgot to say that is not possible the c1 or c2 or c3 be larger than 1. so each cell at most be have 1 value .

The idea , i want to know who users are active in three periods(three columns), I want to distinguish these people with red color from those who are active in two periods( two columns),and from the others who are active in only one period(one column).

so, those are active in three periods with red color

and who are active n two periods with green color,

and who are active in only one period with blue color.

thanks