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

  • SEARCH
  • Home
  • 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 9302369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:14:26+00:00 2026-06-18T23:14:26+00:00

I have the following code in matlab and trying to remove an element from

  • 0

I have the following code in matlab and trying to remove an element from a struct:

function test()
    C = struct;
    C.(sprintf('Ck')) = [1 6 8 9; 8 6 9 7; 7 6 67 6; 65 7 8 7];
    ck_length = length(C.(sprintf('Ck')));
    for i=1:ck_length
        if C.(sprintf('Ck'))(i)> 10
           cleared = rmfield(C.(sprintf('Ck')), C.(sprintf('Ck'))(i));
        end
    end
end

But, when I run the program I get an error as shown below:

>> test
??? Error using ==> rmfield at 19
S must be a structure array.

Error in ==> test at 89
   cleared = rmfield(C.(sprintf('Ck')), C.(sprintf('Ck'))(i));

How can I solve this issue?

Thanks.

  • 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-18T23:14:27+00:00Added an answer on June 18, 2026 at 11:14 pm

    To remove an element from an array you can simply assign it to an empty array ([]):

    C.Ck(ii) = []; % removed the ii-th element of C.Ck.
    

    A few comments:

    1. Use dynamic field names only when you need them to be dynamic. If the field name is always Ck it is much better to access it as C.Ck than C.(sprintf('Ck')).

    2. Try not to use i and j as variable names in matlab.

    3. If you are using ii as an index to C.Ck inside a for loop it is a bit risky to change the size of C.Ck inside the loop. (See e.g., this question).

    4. If you just want to discard elements of C.Ck that are larger than 10, all you need is

      C.Ck( C.Ck > 10 ) = [];
      

      or

      cleared = C.Ck( C.Ck <= 10 );
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code from mathematica and trying to do it with matlab
I have tried the following code in Matlab: function pushbutton5_Callback(hObject, eventdata, handles) global smoothening_level;
I have the following MATLAB code: function START_Callback(a,b) global h; global lastVal; global picture1;
So I have the following matlab code: figure('Properties........'); mainFunctionClass.unzipper(handles); I am trying to create
I have been working on an S-function for matlab in c.But the following code
i have the following error in my matlab function code: ??? Subscript indices must
I have following code for loading image from url in xml parsing endElement method
I have written the following code in MATLAB to process large images of the
I have the following code snippet in Matlab and want to port it to
I have tried following code for creating sparse graph in MATLAB: cm = sparse([1

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.