Emma
Emma

Reputation: 618

plotting from a cell array

clear all
FieldName = {'loc1','loc2','loc3','loc4'};
data = rand(8760,4);

dnew = mat2cell(data,eomday(2011, (1:12))*24,size(data,2));
k = cellfun(@(x)num2cell(nonzeros(tril(corrcoef(x),-1))),dnew','un',0);
out = [FieldName(nchoosek(1:numel(FieldName),2)) [k{:}]];

This example demonstrates the monthly mean correlation between each pair location from 4 sites and is expressed in 'out'. I'm having trouble in plotting this information. I would like to draw a line plot for every pair of locations but where the different line plots have different markers. Also, I would like to insert a legend showing the pair of locations, as denoted in out{1,1} and out{1,2}.

I hope I've been clear in expressing my intentions.

Upvotes: 0

Views: 5652

Answers (1)

user1071136
user1071136

Reputation: 15725

If you're interested in something like this,

Example

You can use the following code:

% Plot data
data = out(:,3:end);
p = plot(cell2mat(data)');

% Generate a cell containing the display names
display_names = cellfun( @(a,b) sprintf('%s - %s', a, b), ...
    out(:,1), out(:,2), 'UniformOutput', false);
legend(display_names);

% Set markers
markers = {'+', '>', '<', '^', 'v', '*', 'hexagram'};
for i=1:(min(length(markers), size(out,1)))
    set(p(i),'Marker',markers{i});
end

Upvotes: 2

Related Questions