matlab input 字符串长度,matlab(七)Input and Output

x=7; disp(x)

disp(solve('x+tan(y)=5','y'))

%想把字符串pi=和变量pi的值显示在一行上,试用disp(′pi=′,pi),回答这是非法的.这时应该用sprintf函数,它可把

%数据按要求的格式转换为字符串,再把它与需要显示的字符串组装成一个长字符串,使显示格式非常灵活,人机界

%面更为友好.如键入【1】

st=sprintf(' circular constant pi=%8.5f',pi)

disp(st)

%结果为

%circular constant pi=3.14159

三、String Manipulation

a=1

b=a/sym(2)

c=sqrt(3)

sym(c)

f='x^3-1';

f(5)

%Converting numbers to character strings[2]

fe=10;

valfe=num2str(fe)

fq=[10.5 20.566]

valf=sprintf('F1=%+15.2f,F2=%4.2e',fq(1),fq(2))

%【1】无论fprintf还是sprintf以同样方式处理输入参量,但fprintf把输出送到显示屏或文件中,

%而sprintf把输出返回到一个字符串中。例如,上面的例子用num2str可重写为

rad=3

area=pi*rad.^2

t=sprintf('A circle of radius %.4g has an area of %.4g ' , rad,

area)

disp(t)

fprintf(' A circle of radius %.4g has an area of

%.4g.\n ' , rad, area)

%这里%.4g是用在函数num2str中的数据格式。%.4g就是用指数或定点标记,不管哪一种更短些,

%只显示至4位数字。除了g格式,还可用e

(指数)和f (定点)转换

%*******************************************

%author: Jianbin Shao

�te:11/24/2015

%********************************************

function OriginData=readdata(filename)

[fileID,message]=fopen(filename,'r');

if

fileID==-1

disp(message);

end

i=0;

while not(feof(fileID))

i=i+1;

OriginData=textscan(fileID, '%f,%f,%f,%f/n');

end

%************************************************

% Import Binary Data with Low-Level I/O

%http://www.analog.com/library/analogdialogue/archives/49-10/four-step-sdr-02.html

%http://www.tutorialspoint.com/matlab/matlab_data_types.htm

%http://www.engdes.com/sigwin/support/download/docs/appnotes.pdf

clc;

clear;

%fileName='sample4010';

fileName='cc.dat';

N=4;

fid=fopen(fileName,'r');

data=fread(fid,[N inf],'uint16');

b =

uint32(rem(data, 4096));

%S=dec2bin(b)

�=str2double(S)

data1=load('sample4010.txt');

%end

_____________________________________________________【3】

Matlab 使用数字产生001、00n这样的字符串 | num2str用法 |sprintf用法 |int2str用法

Matlab把数字转变成str,可以用num2str, sprintf, int2str等

num2str(42.67, '% 10.2f') %returns a 1-by-5 character

array '42.67'.num2str(1.33333,’%.3d’) 把整数部分格式化成3位精度

1.33e000

num2str(1,’%.3d’) 如果是一个整数没有小数部分,对整数部分格式化为3位精度就变为:001

使用MATLAB模拟键盘按键

vb=actxserver('wscript.shell');

!echo

2>demo.txt

winopen('demo.txt');

pause(0.5);

s='I LOVE

MATLAB EVEN BETTER THAN YOU! -baby_wolf';

vb.SendKeys('{CAPSLOCK}');

for

i=1:length(s)

vb.SendKeys(s(i));

pause(0.2);

end

vb.SendKeys(' ^s');

使用MATLAB模拟鼠标:点击右键

import java.awt.Robot;

import java.awt.event.*;

mouse = Robot;

mouse.mousePress(InputEvent.BUTTON3_MASK);

mouse.mouseRelease(InputEvent.BUTTON3_MASK);

使用MATLAB模拟鼠标:移动光标并点击左键

import java.awt.Robot;

import java.awt.event.*;

mouse = Robot;

mouse.mouseMove(60, 70);

mouse.mousePress(InputEvent.BUTTON2_MASK); % //left click press

mouse.mouseRelease(InputEvent.BUTTON2_MASK); %

//left click release

参考文献:

【1】http://www.cnblogs.com/jameskun77/p/3223931.html

【2】 Maurice Charbit; Gerard Blanchet, Digital Signal and Image

Processing using MATLAB, Volume1: Fundamentals, 2nd Edition.

9/24/2014.

【4】Attaway,

Stormy, MATLAB: a pratical introduction programming and problem

solving. 2009.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值