Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Need some help in matlab!

  1. May 11, 2012 #1
    I have a sample date which is a 1000*8 matrix. i want to extract some information and assign them from y data to a some matrices, i want to assign the name of those new matrices automatically, how can i do that? i used the following codes but it gave me an error!

    for i=1:20;
    for j=1:length(data)
    if data(j,1)==i;
    eval['s' num2str(i)(j,:)]=data(j,:);

    Thank you very much.
    Best regards,
  2. jcsd
  3. May 11, 2012 #2


    User Avatar
    Gold Member

    By sure if you can use eval like that, but you could just use sprintf in a strict instead.

    Whats the error?
  4. May 11, 2012 #3


    User Avatar
    Gold Member

    That should b struct not strict (thank you autocorrect)
  5. May 11, 2012 #4
    Dera Pythagorean,
    Thank you.

    The error is:

    Error: File: readr.m Line: 5 Column: 5
    Unbalanced or unexpected parenthesis or bracket.

    How can i use sprintf in a struct to do that?

    i want that program make 20 matrices named s1,s2,...s20. then it check the data if data(j,1) is equal to i, then put it in the marix with the index i.

    can anyone help me?
    Last edited: May 11, 2012
  6. May 11, 2012 #5


    User Avatar
    Gold Member

    here's an example:

    names = {'fred' 'sam' 'al'};
    for ind = 1:length(names)
    s.(names{ind}) = stuff;

    or you can just:

    s.sprintf() = stuff

    check out the help file on sprintf and make sure you know how to use it first.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook