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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:42:25+00:00 2026-05-30T08:42:25+00:00

I have the following example which expresses the type of problem that I’m trying

  • 0

I have the following example which expresses the type of problem that I’m trying to solve:

clear all
textdata = {'DateTime','St','uSt','Ln','W'};
data = rand(365,4);
Final = struct('data',data,'textdata',{textdata})
clear textdata data

From this, Final.data contains values which correspond to the headings in Final.textdata excluding the first (‘DateTime’) thus Final.data(:,1) corresponds to the heading ‘St’… and so on. What I’m trying to do is to create a variable in the workspace for each of these vectors. So, I would have a variable for St, uSt, Ln, and W in the workspace with the corresponding values given in Final.data.

How could this 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-05-30T08:42:26+00:00Added an answer on May 30, 2026 at 8:42 am

    The direct answer to your question is to use the assignin function, like so (edit: just like macduff suggested 10 minutes ago):

    %Starting with a Final structure containing the data, like this
    Final.textdata = {'DateTime','St','uSt','Ln','W'};
    Final.data = rand(365,4);
    
    for ix = 1:4
        assignin('base',Final.textdata{ix+1}, Final.data(:,ix));
    end
    

    However, I strongly discourage using dynamic variable names to encode data like this. Code that starts this way usually ends up as spaghetti code full of long string concatenations and eval statements. Better is to use a structure, like this

    for ix = 1:4
        dataValues(Final.textdata{ix+1}) = Final.data(:,ix);
    end
    

    Or, to get the same result in a single line:

    dataValues = cell2struct(num2cell(Final.data,1), Final.textdata(2:end),2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following RSpec example which is passing: describe UsersController do it should
Good day, If I have for example the documents which have the following fields
I have a URL which can be any of the following formats: http://example.com https://example.com
I have the following example for which I'd like to calculate totals at each
I have following example of the PHP/SQL which worked perfectly when editing one row
I have the following code example for Visual C++ which creates an ActiveX object
I have the following Table example here: http://jsfiddle.net/Lu9y3/ Which is based on the Telerik
I have the following example in Qt in which I try to override the
I have the following example class: Test.h: @interface Test : UIButton { NSString *value;
I have the following example code: class A(object): def __init__(self, id): self.myid = id

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.