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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:12:08+00:00 2026-06-10T02:12:08+00:00

i have strings like these: s{1,2} = ‘string’; s{2,2} = ‘string2’; and in workspace

  • 0

i have strings like these:

s{1,2} = 'string';
s{2,2} = 'string2';

and in workspace structure like this

U.W.string = [2 2.5 3]

I want to check (in loop) s{1,2} or s{2,2} or s{i,2} matches any structure with the same name. If so, assign values from this structure to some variable var(i). How can it be done?

  • 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-10T02:12:09+00:00Added an answer on June 10, 2026 at 2:12 am

    Use isfields to check, if a string is the name of a field in a struct. Then use the syntax struct.(name), where name is a string to access the field. Your code might look something like:

    test = struct('hello', 'world', 'count', 42, 'mean', 10);
    
    fields = {'test', 'count';
              'hello', 'text';
              'more', 'less'};
    values = {pi, 'dummy', -1};
    
    for row = 1 : size(fields, 1)
        for column = 1 : size(fields, 2)
            if isfield(test, fields{row, column})
                test.(fields{row, column}) = values{row};
            end
        end
    end
    

    This converts the initial struct

    test =
        hello: 'world'
        count: 42
        mean: 10
    

    to this one

    test =
        hello: 'dummy'
        count: 3.1416
        mean: 10
    

    A shorter implementation is achieved by removing the inner loop and giving a cell-array to isfields:

    for row = 1 : size(fields, 1)
        %# Note the parenthesis instead of curly braces in the next statement.
        match = isfield(test, fields(row, :));
        if any(match)
            test.(fields{row, match}) = values{row};
        end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have strings(phone numbers) like this: 1112223333 1234567890 And I want to convert these
I want to extract a substring from a string. I have strings like this:
I have strings like this: Car is blue String could also be like this:
I have strings like these: something something [[abcd]] blah blah something something [[xyz|abcd]] blah
I have a string like val1_val2,val3_val4 and I need to split these values to
I have strings like this: http://localhost:2055/web-site-2009/paginas/noticias/**IGP-M recua 0,36% em agosto, aponta FGV**-46.aspx I'd like
I have strings like 84, 03 etc. that I want to convert to Date
I have strings like the ones below in a SQL column. I want to
Say I have strings like these: bunch of other html<a href=http://domain.com/133742/The_Token_I_Want.zip more html and
I have given date strings like these: Mon Jun 28 10:51:07 2010 Fri Jun

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.