• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Matlab小问题合辑【长期稳定更新】

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

Q:

Suppose I have the following string:

s = 'Foo 1.000 3.000 3.554'

I would like to read it with the textscan function as follows.

[name x y z] = textscan(s, '%s %f %f %f')

However, when I do this, I always get the Too many output arguments error.

I think it has to do with the fact that textscan outputs a cell array, but I could not discover how to work around this problem and the desired effect.

A:

You'll need two lines to do what you want. First you get the desired valued into a dummy variable, then distribute the data with deal:

dummy = textscan(s, '%s %f %f %f');
[a,b,c,d] = deal(dummy {:});

Note: After Matlab 7.0, deal() is not neccesary.

 

Q:

i have a file called hello.txt using wordpad which contains the matrix

2 7 3

2 6 9

now i have a vector v = [1 2 3] and i want to add this vector to the hello.txt file so when i open the hello.txt file i should have

2 7 3

2 6 9

1 2 3

how can i do this?

A:

fid = fopen('hello.txt', 'at');
fprintf(fid, '%d %d %d\n', v);
fclose(fid);
 
 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
matlab function rectint发布时间:2022-07-18
下一篇:
delphi中TreeView使用 - 滔Roy发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap