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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:30:29+00:00 2026-05-24T04:30:29+00:00

I have been trying to write a script to process a string of 3D

  • 0

I have been trying to write a script to process a string of 3D variables, eV50, eV60, eV70, etc. (meaning extracted value from the 1950, 1960, 1970 and so on. These 3D variables have the size of 31x145x192.) into a string of 3D output, that is, m1, m2, m3, etc. (dimension of 1x145x192).

This might be pretty straightforward to some of you, but I have been pulling my hair out in the last 24 hours trying to get this working. I tried these two approaches by using loops and EVAL, but I have troubles understanding the ” bracket in the expression, so I guess this is why I couldn’t balance the equation correctly.

*X is the data set eV50, eV60, eV70, etc. (meaning extracted value from the 1950, 1960, 1970, etc.)

Basically I’m trying to turn this script into a loop or some sort of similar:

‘[ m1 v1 ] = extfunc ( eV50 ) ;
[ m2 v2 ] = extfunc ( eV60 ) ;
[ m3 v3 ] = extfunc ( eV70 ) ;
[ m4 v4 ] = extfunc ( eV80 ) ;
[ m5 v5 ] = extfunc ( eV90 ) ;
[ m6 v6 ] = extfunc ( eV100 ) ;
and so on…
‘


Approach 1:

‘[mean vars] = eval([‘extfunc( sprintf(‘,eV%d’, (50:10:80)’) ‘)’]); ‘


Approach 2:

*I have renamed eV50, eV60, eV70 into eV1, eV2, eV3 and so on…

‘ for i=1:6

m(i)=extfunc_h(sprintf(‘eV%d’, i));

end ‘

Usage of extfunc :-

[mean variance] = extfunc(eV50)

In approach 1, I’ve unbalanced equations and approach 2, MATLAB returned the error message

??? Index exceeds matrix dimensions.’


  • 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-24T04:30:30+00:00Added an answer on May 24, 2026 at 4:30 am

    One problem with approach 1 is that each ‘ starts or ends a string, but you want some of them to be part of the string that is supposed to be produced. You need two ‘ for this:

    [mean vars] = eval(['extfunc( sprintf('',eV%d'', (50:10:80)'') '')']);
    

    This will still not do what you want. If you want a string to be produced for each element of 50:10:80, you will need a loop.

    The problem with the second approach is probably that your extfunc returns a vector/array/matrix (for mean; note that you do not record variance this way), but your assigment m(i)= ... can take only scalar values. If mean is a vector, try m(i,:)=....

    However, I would rather question your general approach of dealing with strings and eval here. If it is so easy to rename the variables, why not put them into a cell array or (n+1)-dimensional matrix and have your functions work on actual variable content instead of variable name strings?

    [edit: misleading “of” -> “or” before “(n+1)-dimensional matrix”]

    Edit in response to edited question:
    Although the purpose of SO is not to let other people do your work, what you want seems to be quite straightforward:

    year = 50:10:100;
    for i=1:length(year)
        cmdstr = ['[m' int2str(i) ' v' int2str(i) '] = extfunc(eV' int2str(year(i)) ');'];
        eval(cmdstr);
    end
    

    If you prefer sprintf to char array concatenations for some reason, try

    cmdstr = sprintf('[m%d v%d]=extfunc(eV%d);',i,i,year(i))
    

    instead. I remain unconvinced that using eval and different variable names is a more elegant solution to your problem than collecting eV50, eV60, etc. in one matrix, e.g. eV(:,:,:,1) = eV50; eV(:,:,:,2) = eV60; etc. or a cell array and working on that one, unless your original data source is indeed a MATLAB binary file with variables named thusly.

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

Sidebar

Related Questions

I have been trying to write my own diff3 wrap script for SVN and
I am trying to write an install script for a system I have been
Have been trying to write an awk script which processes a log file, but
I have been trying to write a perl script to get all of the
I have been trying to write a script where I can post data to
I have been trying to write a small app with its own option windows.
I have been trying to write a bare-bones ping scanner using Perl for internal
I have been trying to write an image on a layer using Quartz but
I have been trying to write a regex that will remove whitespace following a
I am new to programming. I have been trying to write a function in

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.