Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7559155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:33:56+00:00 2026-05-30T12:33:56+00:00

The following example resembles a similar problem that I’m dealing with, although the code

  • 0

The following example resembles a similar problem that I’m dealing with, although the code below is merely an example, it is structured in the same format as my actual data set.

clear all

England = struct('AirT',rand(320,1),'SolRad',rand(320,1),'Rain',rand(320,1));
Wales = struct('AirT',rand(320,1),'SolRad',rand(320,1),'Rain',rand(320,1));
Ireland = struct('AirT',rand(320,1),'SolRad',rand(320,1),'Rain',rand(320,1));
Scotland = struct('AirT',rand(320,1),'SolRad',rand(320,1),'Rain',rand(320,1));

Location = struct('England',England,'Wales', Wales, 'Ireland',Ireland,'Scotland',Scotland);

FieldName={'England','Wales','Scotland','Ireland'};
Data = {England.AirT,Wales.AirT,Scotland.AirT,Ireland.AirT};
Data = [FieldName;Data];
Data = struct(Data{:});
Data = cell2mat(struct2cell(Data)');
[R,P] = corrcoef(Data,'rows','pairwise');
R_Value= [FieldName(nchoosek(1:size(R,1),2)) num2cell(nonzeros(tril(R,-1)))];

So, this script would show the correlation between pairs of Air Temperature of 4 locations. I’m looking for a way of also looking at the correlation between ‘SolRad’ and ‘Rain’ between the locations (same process as for AirT) or any variables denoted in the structure. I could do this by replacing the inputs into ‘Data’ but this seems rather long winded especially when involving many different variables. Any ideas on how to do this? I’ve tried using a loop but it seems harder than I though to try and get the data into the same format as the example.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:33:57+00:00Added an answer on May 30, 2026 at 12:33 pm

    Let’s see if this helps, or is what you are thinking:

    clear all
    
    England = struct('AirT',rand(320,1),'SolRad',rand(320,1),'Rain',rand(320,1));
    Wales = struct('AirT',rand(320,1),'SolRad',rand(320,1),'Rain',rand(320,1));
    Ireland = struct('AirT',rand(320,1),'SolRad',rand(320,1),'Rain',rand(320,1));
    Scotland = struct('AirT',rand(320,1),'SolRad',rand(320,1),'Rain',rand(320,1));
    
    Location = struct('England',England,'Wales', Wales, 'Ireland',Ireland,'Scotland',Scotland);
    
    % get all the location fields
    FieldName = transpose(fieldnames(Location));
    % get the variables recorded at the first location
    CorrData = fieldnames(Location.(FieldName{1}));
    % get variables which were stored at all locations(just to be safe,
    % we know that they are all the same)
    for ii=2:length(FieldName)
      CorrData = intersect(CorrData,fieldnames(Location.(FieldName{ii})));
    end
    
    % process each variable that was recorded
    for ii=1:length(CorrData)
      Data = cell(1,length(FieldName));
      % get the variable data from each location and store in Data
      for jj=1:length(FieldName)
        Data{jj} = Location.(FieldName{jj}).(CorrData{ii});
      end
      % process the data
      Data = [FieldName;Data];
      Data = struct(Data{:});
      Data = cell2mat(struct2cell(Data)');
      [R,P] = corrcoef(Data,'rows','pairwise');
      R_Value= [FieldName(nchoosek(1:size(R,1),2)) num2cell(nonzeros(tril(R,-1)))];
      % display the data, sounds good right?
      fprintf(1,'Correlation for %s\n',CorrData{ii});
      for jj=1:size(R_Value,1)
        fprintf(1,'%s\t%s\t%f\n',R_Value{jj,1},R_Value{jj,2},R_Value{jj,3});
      end
    end
    

    Let me know if I misunderstood, or if this is more involved than what you were thinking. Thanks!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see a lot of code, particularly in Apple example code, that resembles the
Example: Suppose in the following example I want to match strings that do not
In the following example should I expect that values.size() will be called every time
I'm running PyDev 2.2.3 on Aptana 3.0 The following example project resembles my current
The following example is bad, because it has code repetition. For example, if we
In the following example, is there a way to construct the object such that
The following example code compiles under gcc and works as I would hope. It
The following example code will load a jqGrid (this code works) ... jQuery(document).ready(function ()
Following example code from the libpcap documentation yields the following code which should report
Following Example 2 in http://knockoutjs.com/documentation/hasfocus-binding.html JSFiddle showing problem: http://jsfiddle.net/hXqFu/2/ It works great for both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.