Solving MATLAB Error: Assigning Names to New Matrices

  • Context: MATLAB 
  • Thread starter Thread starter mathia
  • Start date Start date
  • Tags Tags
    Matlab
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 2K views
mathia
Messages
15
Reaction score
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
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:
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.