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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:57:27+00:00 2026-05-20T01:57:27+00:00

clc clear all n=3; % Three column j=1; for ii=1:n C{ii}=cell(20,1) % Each column

  • 0
clc 
clear all 
n=3;  % Three column
j=1;


for ii=1:n
    C{ii}=cell(20,1) % Each column got 20 rows. 
end 

for k=1:2

    for l=1:3

        for m=1:2


    X{j}='No strings attched';  % stored all generated data. 
    j=j+1;


   % I would like to know which column I should store the data. 
   %Randomly picking a column number 

    r=ceil(rand(1,1)*n)   

    % Storing in that column. 

    ***C{r}='No strings attched';***

        end 

    end 

end

I’ve generated three columns and 20 rows. Within a nested loop, I generates a data and stored all of them. Next, I’m picking up a clum randomly and storing the data generated. However, I can see total number of generated data is 12. Which should in columns 1,2,1,3,1,*2,1*,2,3,1,2,1. Hence when I check C(1), it should show six data. But, I couldn’t figure out how to do that. Any help appreciated.

  • 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-20T01:57:28+00:00Added an answer on May 20, 2026 at 1:57 am

    At the end, you’re assigning a string to C{r}, which is a 20×1 cell. You then need to select a row from that 20×1 cell. For example, C{r}{1}.

    Next, I’m not exactly sure what you’re trying to do, but it sounds like, you want to have C{1}{1:6} to have data, but C{1}{7:20} should be empty. There are two ways to do this. The easiest way is actually to initialize the cells to cell(0, 1) and assign into C{r, end+1}, but this will be very slow if you have a lot of data. A better way is to stick with the cell(20, 1) initialization. You also need to add an array storing the actual length of the array (how many elements in the array are used) as opposed to the capacity (how many it can hold, which is 20). Or, instead of using an array, you could add it as the 2nd dimension of the C array. Your choice. Then your assignment would be utilize that count like so:

    %Outside Loop
    counts = zeros(1, n);
    
    %Inside Loop
    C{r}{counts(r) + 1} = blah blah
    counts(r) = counts(r) + 1;
    

    If you have more than 20 elements, you should double the capacity of the cell.
    Finally, to see the data stored in the first entry in C, you can use:

    %After Loop
    C{1}{1:counts(1)}
    

    Note: I don’t have access to Matlab at the moment so I’m not 100% sure it all parses correctly, but that’s the main idea.

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

Sidebar

Related Questions

clc clear all ii=1; S =cell(size(30,1)); % cell size. for ii=1:1:3 rand_id= rand(1,1) *3;
How do i apply these Gabor filter wavelets on an image ? close all;
I used nlfilter for a test function of mine as follows: function funct clear
FFT and changing frequency and vectorizing for loop Greetings All I can increase and
I have a problem in storing the data in matrix in for and if
I have a script this MATLAB script: function semjudge clc; name = input('Name: ','s');
Preamble: I'm working at heavy-loaded applicaion that produces large data arrays. I wrote the
When compiling the code below with cl /c /clr /W4 the compiler says warning
Say I have a function a = b / c and I ask the
I am following the example on this page : Example of 10-fold SVM classification

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.