zoukankan      html  css  js  c++  java
  • Matlab小问题合辑【长期稳定更新】

    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);
     
     
  • 相关阅读:
    捷微商城小程序上线啦~
    JEECG 新版在线文档WIKI正式发布
    https 详解
    css 3 新特性
    js 基础(一)
    BFC
    .Net、C# 汉字转拼音,简体繁体转换方法
    丰富“WinForms” 的一个别样"项目"(学生管理)
    学生管理系统1
    学生管理系统
  • 原文地址:https://www.cnblogs.com/ShaneZhang/p/3092310.html
Copyright © 2011-2022 走看看