Plot Graph Based Pair of Columns

1 Ansicht (letzte 30 Tage)
Amritpal Kaur
Amritpal Kaur am 19 Apr. 2016
Beantwortet: Arnab Sen am 25 Apr. 2016
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.
  1 Kommentar
Joachim Schlosser
Joachim Schlosser am 19 Apr. 2016
  1. What exactly are you trying to plot here?
  2. Could you please post the first 10-30 lines of the dataset?
  3. Could you please post the code you've tried so far?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Arnab Sen
Arnab Sen am 25 Apr. 2016
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]

Weitere Antworten (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by