MATLAB: Plot Graph Based Pair of Columns

plot

Hello,
I have a dataset like this.
+---------+---------+------------+------------+
| string1 | string2 | col3 | col4 |
+---------+---------+------------+------------+
| abc | xyz | random_num | random_num |
+---------+---------+------------+------------+
| abc | mno | random_num | random_num |
+---------+---------+------------+------------+
| abc | xyz | random_num | random_num |
+---------+---------+------------+------------+
So I have to plot col3 vs. col4 where the pair string1, string2 are repeating, meaning, say for the example above, my plots will be the 1st and 3rd row. string1, string2 can have different but reappearing values. This data set is huge and contains many repeating string1, string2 pairs. How to do that! Thanks.

Best Answer

Hi Amritpal,
You may consider the script below for this purpose
toPlot=zeros(size(data(:,1)))
x=[];
y=[];
for i=1:size(data(:,1))
if(toPlot(i)==1)
x(end+1)==data{i,3};
y(end+1)==data{i,4};
continue;
end
col1=data{i,1};
col2=data{i,2};
appearPos=find(strcmp(data(:,1),data(i,1))& strcmp(data(:,2),data(i,2)));
% if size(appearTimes>1)
toPlot(appearPos)=1;
x(end+1)=data{i,3};
y(end+1)=data{i,4};
% end
end
plot(x,y);
Here we are storing the data to plot in x and y array based on the flag set in toPlot array which we set if col1 and col2 combination is repeated.
In my case the 'data' cell array is stored like below format:
>> data
data =
'abc' 'xyz' [4] [3]
'abc1' 'xyz1' [2] [8]
Related Question