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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:51:34+00:00 2026-05-30T07:51:34+00:00

I have a folder A that contains folders B and C A–B C–| –|mat

  • 0

I have a folder A that contains folders B and C

A--B
   C--|
     --|mat file  

at the folder level, I have a startup scrit and I want from this script to load data available in data.mat file available in C1 folder.

so from my script A_script.m , I did :

load('C/C1/data.mat');

content of script file :

function data_startup
%WHC_PROJECT_STARTUP
bdclose all;
load('B\C\data_v2.0.mat');

but this does nothing,data not loaded and no error raised !
can someone help me ?

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-05-30T07:51:35+00:00Added an answer on May 30, 2026 at 7:51 am

    What I understand from the question is you have a data stored in a .mat-file in a sub-folder and you want to use it for a some kind of initialization. If you expect to use them later from the base workspace, then one possibility would be to change the function to a script:

    %WHC_PROJECT_STARTUP
    bdclose all;
    load(fullfile('B', 'C', 'data_v2.0.mat'));
    

    I would recommend here the use of the function

    fullfile('B', 'C', 'data_v2.0.mat')
    

    because this makes you code platform-independent (Linux uses ‘/’, Windows ‘\’). If you want the content of the .mat-file loaded in you base workspace, just save the code above as script and execute it.

    If you insist to read the file in an function and use it later in base workspace, then look at the following code

    function data_startup()
    %WHC_PROJECT_STARTUP
    bdclose all;
    temp_data=load(fullfile('B', 'C', 'data_v2.0.mat')); % will be loaded as structure
    file_variables=fieldnames(temp_data);% get the field names as cell array
    for ii=1:length(file_variables)
       % file_variables{ii} - string of the field name
       % temp_data.(file_variables{ii}) - dynamic field reference
       assignin('base', file_variables{ii}, temp_data.(file_variables{ii}));
    end
    

    The code should work, right now I am at home and can not test it, sorry.

    I would prefer the script solution, assigning variables from one workspace to another could lead to problems with the support and the extension of the code (suddenly variables are created and you do not see where they come from).
    Here are some more examples how to access fields of a structure dynamically.

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

Sidebar

Related Questions

I have a folder, c:\websites\test , and it contains folders and files that were
I have a folder, that contains other folders, which may or may not contain
I have a script that is copying a folder that contains a couple sub
I have a folder X:/EmpInfo that contains many different folders. Each of these folders
I have a folder foo that is included in gitignore: - .gitignore (this contains
I have a folder that contains 1000+ sub folders. In each subfolder there are
I have an array of folders/files that looks like this: Array ( [Root Folder
I have a folder/directory that contains some sub directories. Only those sub folders contain
I have an app that contains top level folder with subfolders in the app's
I have a folder in NTFS that contains tens of thousands of files. I've

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.