Solving MATLAB Error: Assigning Names to New Matrices

  • MATLAB
  • Thread starter mathia
  • Start date
  • Tags
    Matlab
In summary, the individual is trying to extract information from a 1000*8 matrix and assign it to new matrices with automatically generated names. They attempted to use the eval function but encountered an error. They are considering using the sprintf function instead and are seeking assistance with implementing it.
  • #1
mathia
15
0
Hi,
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!

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

Thank you very much.

Mathias
 
Physics news on Phys.org
  • #2
By sure if you can use eval like that, but you could just use sprintf in a strict instead.

Whats the error?
 
  • #3
That should b struct not strict (thank you autocorrect)
 
  • #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:
  • #5
here's an example:

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

or you can just:

s.sprintf() = stuff

check out the help file on sprintf and make sure you know how to use it first.
 

1. What does the error "Assigning Names to New Matrices" mean?

This error occurs when you are trying to assign a name to a new matrix in MATLAB, but the name you are using is already assigned to another matrix or variable.

2. How can I fix this error?

To fix this error, you will need to choose a different name for your new matrix. Make sure the name is not already in use for another matrix or variable in your code.

3. Can I use the same name for multiple matrices in MATLAB?

No, MATLAB does not allow you to use the same name for multiple matrices. Each matrix must have a unique name in order to avoid errors.

4. What happens if I try to assign the same name to two different matrices in MATLAB?

If you try to assign the same name to two different matrices in MATLAB, you will receive the "Assigning Names to New Matrices" error. The program will not know which matrix you are referencing when using that name, causing confusion and potential errors in your code.

5. Is there a way to check if a name is already in use for a matrix in MATLAB?

Yes, you can use the "exist" function in MATLAB to check if a name is already in use for a matrix. If the function returns a value of 1, then the name is already in use. If it returns a value of 0, then the name is available to use for a new matrix.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
859
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
Back
Top