Tags: 3s24, 6s37, cat, command, friends, matlab, programming, s11, stick
how to use cat command
On Programmer » Matlab
5,114 words with 9 Comments; publish: Wed, 30 Apr 2008 23:09:00 GMT; (20046.88, « »)
hi,my friends,i need your help.
my problem is now i have some data.
s1=[1,2,3]
s2=[4,5,6]
s3=[7,8,9]
...
now i want to stick them together
total=[1,2,3
4,5,6
7,8,9
...]
I use load loop to put all data into matlab.the next step is to use cat
to stick them.but for the name is s1,s2,s3.i do not know hot to do it
.thank u guys first.
http://matlab.itags.org/q_matlab_28949.html
All Comments
Leave a comment...
- 9 Comments

- dog75 wrote:
>
> hi,my friends,i need your help.
> my problem is now i have some data.
> s1=[1,2,3]
> s2=[4,5,6]
> s3=[7,8,9]
> ...
> now i want to stick them together
> total=[1,2,3
> 4,5,6
> 7,8,9
> ...]
> I use load loop to put all data into matlab.the next step is to use
> cat
> to stick them.but for the name is s1,s2,s3.i do not know hot to do
> it
> .thank u guys first.
>
here are two quick ways:
cat(2,s1,s2,s3)
or
[s1 s2 s3]
see doc cat
arun
#1; Wed, 30 Apr 2008 23:10:00 GMT

- hi,in fact there are about 500 numbers like s1,s2,s3,s4...s500
i can not simply use cat command .that is my problem.thank you for your
response
#2; Wed, 30 Apr 2008 23:11:00 GMT

- dog75 wrote:
>
> hi,in fact there are about 500 numbers like s1,s2,s3,s4...s500
> i can not simply use cat command .that is my problem.thank you for
> your
> response
>
When you say that you "used a loop to put the data into matlab," what
do you mean? Are you importing the data from somewhere.
If you have all the variable names in a cell array such as
arg = {s1 s2 ... s100};
blah = cat(2,arg{:});
would work.
#3; Wed, 30 Apr 2008 23:12:00 GMT

- Arun Srantham wrote:
>
> dog75 wrote:
> for
> When you say that you "used a loop to put the data into matlab,"
> what
> do you mean? Are you importing the data from somewhere.
> If you have all the variable names in a cell array such as
> arg = {s1 s2 ... s100};
> blah = cat(2,arg{:});
> would work.
Try something like this:
cub = char;
for i=1:N
bull = load(['s',int2str(i),'.mat']);
cub = [cub struct2cell(bull)];
end
blah = cat(2,cub{:});
I'm sure someone can make this neater and faster but this works.
arun
#4; Wed, 30 Apr 2008 23:13:00 GMT

- sorry to both u again,it show the fault
? Error using =3D=3D> struct2cell
Function 'struct2cell' is not defined for values of class 'double'.
Error in =3D=3D> C:\Documents and
Settings\wr\=E6=A1=8C=E9=9D=A2\0.02-0.5test\matlab\loadfile.m
On line 8 =3D=3D> cub =3D [cub struct2cell(bull)];
Arun Srantham =E5=86=99=E9=81=93=EF=BC=9A
> dog75 wrote:
> here are two quick ways:
>=20
> cat(2,s1,s2,s3)
> or
> [s1 s2 s3]
>=20
> see doc cat
>=20
> arun
#5; Wed, 30 Apr 2008 23:14:00 GMT

- dog75 wrote:
>
> sorry to both u again,it show the fault
> ? Error using ==> struct2cell
> Function 'struct2cell' is not defined for values of class 'double'.
> Error in ==> C:\Documents and
> Settings\wr\桌面\0.02-0.5test\matlab\loadfile.m
> On line 8 ==> cub = [cub struct2cell(bull)];
>
You got an error since we are most likely reading in the variables
from the file differently. I loaded from a .mat file and you might
be loading from a .txt file. From a .mat file they are loaded into
the variable 'bull'. Since the error tells me that you loading into
class 'double', then you don't need the 'struct2cell' command and
might just be able to use:
cub = char;
for i=1:N
bull = load(['s',int2str(i),'.mat']);
cub = [cub bull];
end
hope this helps
#6; Wed, 30 Apr 2008 23:15:00 GMT

- i tried .and seemed cub=[cub bull]is not correct:(#7; Wed, 30 Apr 2008 23:16:00 GMT

- dog75 wrote:
>
> i tried .and seemed cub=[cub bull]is not correct:(
>
The differences in our results must be due to the file format. Do
you have two test files that you could post?
arun
#8; Wed, 30 Apr 2008 23:17:00 GMT

- s1.txt:
0.0000 0.0000 0.0000 0.0560 0.0927 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
s2.txt:
0.0000 0.0000 0.0995 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
and this is my problem/
my problem is now i have 500files named s1 tos500.each file like this
s1=[1,2,3]
s2=[4,5,6]
s3=[7,8,9]
...
now i want to stick them together to one array or matrix.
first i use
N=4
for i=1:N
load(['s',int2str(i),'.txt']);
load 500 files to matlab.
then i want to use cat to stick them .the problem is each name of the
array is not number ,they are s1,s2,s3...s500.How can i use for loop to
put them together.
#9; Wed, 30 Apr 2008 23:18:00 GMT