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 9134111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:36:12+00:00 2026-06-17T08:36:12+00:00

I am a total beginner in MATLAB and I hope to find some help

  • 0

I am a total beginner in MATLAB and I hope to find some help here. I have some model prediction results for 80 individuals alltogether in one large matrix. I need to extract the data for each individual from the big matrix, assign them in a new variable/matrix, do some extra calculations and then plot certain information as needed.

To do so, I am trying to write a script with a loop function but in a complicated, or maybe more accurately: in a primitive way!

Simplified Example:
My matrix is called: All_Indi_Data …. its dimension is: 600 rows x 21 columns

%Column 1: grouping variable (e.g., code or ID with values 1,2,3,4,5, etc.); 
%Column 2: independent var.;
%Column 3: t;
%Column 4: OBS;
%Column 5: PRED;



i= length (All_Indi_Data);

%% First Indi.
q=1;    % indicating the ID of the indi for which I want to extract the data
j=1;    % variable added to insure writing start from the first row

for r=1:i
if All_Indi_Data (r,1)==q
  Indi_1 (j,1:21) = All_Indi_Data (r,1:21)
  j=j+1
end

end

%% Second Indi.
q=q+1
j=1

for r=1:i
if All_Indi_Data (r,1)==q
   Indi_2 (j,1:21) = All_Indi_Data (r,1:21)
   j=j+1
end

end

.
.
.

1) My first question is: can I allocate these data in new variables (Indi_1, Indi_2, ect.) in a more simple way with or without the loop function?!!! I would appreciate your help a lot.

2) Is there any code or any way to plot these selected parts (according to the grouping variable, e.g. data for Indi_1) from the previously mentioned big matrix without wasting a lot of time and space (wto recopying the core part of the code again and again) for the script, and using the loop function?! in other words, I would like to detect – with loop function & the grouping variable- which values are of interest and then to plot them (e.g. data in colum 3 with data from column 4 for each individual, starting from the first to the last)?!

I hope that I described my problem clearly and hope to hear something from the expert guys 🙂 …

Thanks a lot in advance ..

  • 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-06-17T08:36:13+00:00Added an answer on June 17, 2026 at 8:36 am

    Try the following code:

    for idx=1:80
        pos=find(All_Indi_Data(:,1)==idx);
        eval(['Indi_' num2str(idx) '=All_Indi_Data(pos,:);']);
    end
    

    What I do is: in each iteration, I search for a value of the ID, indicated in the variable idx. Note that I do not use ´i´ as the name of a variable, because Matlab uses it and ´j´ and the imaginary unit for complex numbers and that could cause problems.

    Then, using find I search for the position (or positions) of All_Indi_Data in which I can find the information of that individual. Now I have in the variable ´pos´ the indexes of the rows in which there is information for the individual of interest.

    Finally, using eval I extract the data for each individual into a variable. Note that eval combined with a loop makes it easy to create lots of variables. I indicate the rows I want to extract with ´pos´ and, as I want all the columns, I use just ´:´ (you could use ´1:21´ too).

    With another similar loop you can plot the information you want. For example:

    for idx=1:80
            eval(['x=Indi_' num2str(idx) ';']); 
            % Now I have in X the information for this individual
            %Plot the columns of x I want
            plot(x(:, 3), x(:,4));
            pause; %stay here until a press a key
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a total beginner's question, but I have yet to find an
I am a total beginner with Xcode and Objective C, but I have some
Hello I am total beginner in cobol and needing some homework help. I am
I have stumped on this as I am a total beginner in MySql. Here
I'm a total beginner so I apologize if this question is elementary. I have
I am a total Beginner in C++ and programming generaly. I have watched a
I am a total beginner to programming and Django so I'd appreciate help that
Total beginner question about jQuery: I have a Form that contains several TextBoxes (input
I am a complete, total beginner in programming, although I do have knowledge of
I m a total beginner in iOS development and need a bit of help:

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.