请问在matlab中fliplr sprintf(...

1574人阅读
一、&介绍新版newff
= newff(P,T,[S1 S2...S(N-l)],{TF1 TF2...TFNl}, BTF,BLF,PF,IPF,OPF,DDF)
Description
newff(P,T,[S1 S2...S(N-l)],{TF1 TF2...TFNl}, BTF,BLF,PF,IPF,OPF,DDF) takes
several arguments
R x Q1 matrix of Q1 sample R-element input vectors
SN x Q2 matrix of Q2 sample SN-element target vectors
Size of ith layer, for N-1 layers, default = [ ].
(Output layer size SN is determined from T.)
Transfer function of ith layer. (Default = 'tansig' for
hidden layers and 'purelin' for output layer.)
Backpropagation network training function (default = 'trainlm')
Backpropagation weight/bias learning function (default = 'learngdm')
Row cell array of input processing functions. (Default = {'fixunknowns','removeconstantrows','mapminmax'})
Row cell array of output processing functions. (Default = {'removeconstantrows','mapminmax'})
Data divison function (default = 'dividerand')
Here is a problem consisting of inputs P and targets T to be solved with a
= [0 1 2 3 4 5 6 7 8 9 10];T = [0 1 2 3 4 3 2 1 2 3 4];
Here a network is created with one hidden layer of five neurons.
= newff(P,T,5);
The network is simulated and its output plotted against the targets.
= sim(net,P);plot(P,T,P,Y,'o')
The network is trained for 50 epochs. Again the network's output is plotted.
·&net.trainParam.epochs
= 50;net = train(net,P,T);Y = sim(net,P);plot(P,T,P,Y,'o')
二、&新版newff与旧版newff调用语法对比
比如输入input(6*1000),输出output为(4*1000),那么
旧版定义:net=newff(minmax(input),[14,4],{'tansig','purelin'},'trainlm');
新版定义:net=newff(input,output,14,{'tansig','purelin'},'trainlm');
比如输入input(6*1000),输出output为(4*1000),那么
旧版定义:net=newff(minmax(input),[49,14,4],{'tansig','tansig','tansig'},'traingdx');
新版定义:net=newff(input,output,
[49,14], {'tansig','tansig','tansig'},'traingdx');
三、&旧版newff使用方法在新版本中使用
提示:旧版本定义的newff虽也能在新版本中使用,但会有警告,警告如下:
Warning: NEWFF used in an obsolete way.
& In obs_use at 18
&&In newff&create_network at 127
&&In newff at 102
&&&&&&&&&&See help for NEWFF to update calls to the new argument list.
四、&新版newff与旧版newff使用的训练效果对比
&&&&&旧版本:旧用法训练次数多,但精度高&&
新版本:新用法训练次数少,但精度可能达不到要求
造成上述原因是:
程序里面的权值、阈值的初始值是随机赋值的,所以每次运行的结果都会不一样,有好有坏。
你可以把预测效果不错的网络的权值和阈值作为初始值。
具体可以查看net.iw{1,1}、net.lw{2,1}、net.b{1}、net.b{2}的值。
现在给一个完整的例子
&%%&清空环境变量
%%&训练数据预测数据
data=importdata('test.txt');
%从1到768间随机排序
k=rand(1,768);
[m,n]=sort(k);
%输入输出数据
input=data(:,1:8);
output =data(:,9);&
%随机提取500个样本为训练样本,268个样本为预测样本
input_train=input(n(1:500),:)';
output_train=output(n(1:500),:)';
input_test=input(n(501:768),:)';
output_test=output(n(501:768),:)';&
%输入数据归一化
[inputn,inputps]=mapminmax(input_train);&
%% BP网络训练
% %初始化网络结构
net=newff(inputn,output_train,10);&
net.trainParam.epochs=1000;
net.trainParam.lr=0.1;
net.trainParam.goal=0.0000004;
%%&网络训练
net=train(net,inputn,output_train);&
%% BP网络预测
%预测数据归一化
inputn_test=mapminmax('apply',input_test,inputps);&
%网络预测输出
BPoutput=sim(net,inputn_test);&
%%&结果分析
%根据网络输出找出数据属于哪类
BPoutput(find(BPoutput&0.5))=0;
BPoutput(find(BPoutput&=0.5))=1;&
%%&结果分析
%画出预测种类和实际种类的分类图
plot(BPoutput,'og')
plot(output_test,'r*');
legend('预测类别','输出类别')
title('BP网络预测分类与实际类别比对','fontsize',12)
ylabel('类别标签','fontsize',12)
xlabel('样本数目','fontsize',12)
ylim([-0.5 1.5])&
%预测正确率
rightnumber=0;
for i=1:size(output_test,2)
&&&&if BPoutput(i)==output_test(i)
&&&&&&&&rightnumber=rightnumber+1;
rightratio=rightnumber/size(output_test,2)*100;
sprintf('测试准确率=%0.2f',rightratio)
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:16277次
排名:千里之外
转载:11篇
(1)(1)(1)(1)(3)(3)(5)查看: 19554|回复: 10|关注: 0
matlab中fprintf保存string字符到txt文档换行问题的分析
关注者: 19
随手写的,有点乱。如果懒得浪费时间看前面的话,直接看最后几句话。
最近几次在论坛中看到有会员提问关于matlab中fprintf保存string字符到txt文档换行问题的分析,我没有在论坛中搜索,不知道是否有相应的问题的解决方法,只是自己做一下分析,并分享一下。
1 我们先做个小实验,
fid=fopen('Outputdata.txt','wt');
str=['abc';'bed'];
fprintf(fid,'%s',str)
fclose(fid);
结果发现,打开txt文档一看,结果只有一行。其结果和str(:)的顺序一样。
如果是fprintf(fid,'%s\n',str)呢,发现在txt文档中实际有两行,只是第二行是一个空行而已。这就说明\n是起了作用的。输入
a=sprintf('%s\n', str);
&& size(a)
& &&&1& &&&7
可以发现a实际上是七个字符,最后一个字符是换行符。因此换行当然是在最后了。
那么有人问,我如果直接在str中添加\n呢?str=['a\n';'bed'];
sprintf('%s', str)
显然也不能够实现换行的。
正确的实现方法是:
fid=fopen('Outputdata.txt','wt');
str=['abc';'bed'];
fprintf(fid,'%s \n',str(i,:));
这样的话,在每一行中添加了一个/n。
lose(fid);
[ 本帖最后由 edifiers2008 于
22:02 编辑 ]
厉害啊,高手
text文本换行我用的是:fprintf(fid,'\r\n',str(i,:));
谢谢高手指点,我还正发愁呢
关注者: 1
楼主没有发现,在windows下,用sprintf创造字符串时,只要指定\r\n,然后fprintf就可以换行吗?
当然这只是对print到文件的情况
如果直接fprintf到command window,那么用\n就可以了
回复 1# edifiers2008 的帖子
:) O(∩_∩)O谢谢楼主和5楼的高手!
谢谢啊,解决大问题了
感谢分享 多谢了
为什么我用“\r\n”时,打开文本后第一行是空着的呢
在matlab gui中如何才能将edit text 的数据保存到txt中并换行?
站长推荐 /1
Powered by小木虫 --- 500万硕博科研人员喜爱的学术科研平台
&&查看话题
matlab 去除坐标轴上的一段
请问在matlab中怎么去掉坐标轴上的一段?比如Y轴,范围是0-100,把2-98这个范围去掉,应该怎么处理?谢谢
提示:Error: File: BreakPlot.m Line: 69 Column: 15
Expression or statement is incomplete or incorrect.
该怎么处理?另外可以不用z字去除?谢谢指导
y=-4480:0;
breakplot(x,y,'bd-',-4459,-35,'line');
???&&Index of element to remove exceeds matrix dimensions.
Error in ==> BreakPlot at 81
菜鸟不懂怎么来说····
求高手讲解····:cry:
研究生必备与500万研究生在线互动!
扫描下载送金币MATLAB Numbers
MATLAB - Numbers
Advertisements
MATLAB supports various numeric classes that include signed and unsigned integers and single-precision and double-precision floating-point numbers. By default, MATLAB stores all numeric values as double-precision floating point numbers.
You can choose to store any number or array of numbers as integers or as single-precision numbers.
All numeric types support basic array operations and mathematical operations.
Conversion to Various Numeric Data Types
MATLAB provides the following functions to convert to various numeric data types &
Converts to double precision number
Converts to single precision number
Converts to 8-bit signed integer
Converts to 16-bit signed integer
Converts to 32-bit signed integer
Converts to 64-bit signed integer
Converts to 8-bit unsigned integer
Converts to 16-bit unsigned integer
Converts to 32-bit unsigned integer
Converts to 64-bit unsigned integer
Create a script file and type the following code &
x = single([5.32 3.47 6.28]) .* 7.5
x = double([5.32 3.47 6.28]) .* 7.5
x = int8([5.32 3.47 6.28]) .* 7.5
x = int16([5.32 3.47 6.28]) .* 7.5
x = int32([5.32 3.47 6.28]) .* 7.5
x = int64([5.32 3.47 6.28]) .* 7.5
When you run the file, it shows the following result &
Let us extend the previous example a little more. Create a script file and type the following code &
x = int32([5.32 3.47 6.28]) .* 7.5
x = int64([5.32 3.47 6.28]) .* 7.5
x = num2cell(x)
When you run the file, it shows the following result &
[1,1] = 38
[1,2] = 23
[1,3] = 45
Smallest and Largest Integers
The functions intmax() and intmin() return the maximum and minimum values that can be represented with all types of integer numbers.
Both the functions take the integer data type as the argument, for example, intmax(int8) or intmin(int64) and return the maximum and minimum values that you can represent with the integer data type.
The following example illustrates how to obtain the smallest and largest values of integers. Create a script file and write the following code in it &
% displaying the smallest and largest signed integer data
str = 'The range for int8 is:\n\t%d to %d ';
sprintf(str, intmin('int8'), intmax('int8'))
str = 'The range for int16 is:\n\t%d to %d ';
sprintf(str, intmin('int16'), intmax('int16'))
str = 'The range for int32 is:\n\t%d to %d ';
sprintf(str, intmin('int32'), intmax('int32'))
str = 'The range for int64 is:\n\t%d to %d ';
sprintf(str, intmin('int64'), intmax('int64'))
% displaying the smallest and largest unsigned integer data
str = 'The range for uint8 is:\n\t%d to %d ';
sprintf(str, intmin('uint8'), intmax('uint8'))
str = 'The range for uint16 is:\n\t%d to %d ';
sprintf(str, intmin('uint16'), intmax('uint16'))
str = 'The range for uint32 is:\n\t%d to %d ';
sprintf(str, intmin('uint32'), intmax('uint32'))
str = 'The range for uint64 is:\n\t%d to %d ';
sprintf(str, intmin('uint64'), intmax('uint64'))
When you run the file, it shows the following result &
ans = The range for int8 is:
-128 to 127
ans = The range for int16 is:
-32768 to 32767
ans = The range for int32 is:
ans = The range for int64 is:
ans = The range for uint8 is:
ans = The range for uint16 is:
0 to 65535
ans = The range for uint32 is:
ans = The range for uint64 is:
Smallest and Largest Floating Point Numbers
The functions realmax() and realmin() return the maximum and minimum values that can be represented with floating point numbers.
Both the functions when called with the argument 'single', return the maximum and minimum values that you can represent with the single-precision data type and when called with the argument 'double', return the maximum and minimum values that you can represent with the double-precision data type.
The following example illustrates how to obtain the smallest and largest floating point numbers. Create a script file and write the following code in it &
% displaying the smallest and largest single-precision
% floating point number
str = 'The range for single is:\n\t%g to %g and\n\t %g to
sprintf(str, -realmax('single'), -realmin('single'), ...
realmin('single'), realmax('single'))
% displaying the smallest and largest double-precision
% floating point number
str = 'The range for double is:\n\t%g to %g and\n\t %g to
sprintf(str, -realmax('double'), -realmin('double'), ...
realmin('double'), realmax('double'))
When you run the file, it displays the following result &
ans = The range for single is:
-3.40282e+38 to -1.17549e-38 and
1.17549e-38 to
3.40282e+38
ans = The range for double is:
-1.7 to -2.2 and
& Copyright 2016. All Rights Reserved.

我要回帖

更多关于 matlab中fliplr 的文章

 

随机推荐