在MATLAB中,我在文件名A.txt中有一个1 X 20列的字符串数据向量.
%Input in A.txt:
60N
61N
50S
51S
Run Code Online (Sandbox Code Playgroud)
目标:以整数读取数据列并表示N.
积极,S积极.
所以输出将是:
60
61
-50
-51
Run Code Online (Sandbox Code Playgroud)
我已经研究了其他帖子,应用str2num double.我完全陷入了困境.
在Perl中,打开函数的大写TEXT的目的是什么?它是模块还是内置功能?
这是代码:
#!/usr/bin/perl -w
use v5.10.0;
use warnings;
my $filename = "<file.txt";
open(TEXT, $filename) or die "Can't open file.\n";
Run Code Online (Sandbox Code Playgroud) 在MATLAB中,我试图建立一个for循环以绘制x,y诸如x1,y1, x2,y2和的下标对x3,y3。目标是for循环将下标传递给x和y并绘制3个数字。
这是代码:
x1 = rand(10,1);
y1 = rand(10,1);
x2 = rand(10,1);
y2 = rand(10,1);
x3 = rand(10,1);
y3 = rand(10,1);
for i = 1:3
plot(x(i),y(i))
end
Run Code Online (Sandbox Code Playgroud)
但是,我得到一个错误。那么,如何使用for循环对数据进行下标绘制呢?
在MATLAB中,我有以下脚本输出数据:
A1 = [1 2;3 4]
A2 = [2 2; 4 5]
A3 = [3 5; 7 8]
Run Code Online (Sandbox Code Playgroud)
我需要创建一个for循环来逐步执行每个变量和绘图.就像是:
for i = 1:3
plot(A(i))
end
Run Code Online (Sandbox Code Playgroud)
所以A1会产生一个情节.A2将生成一个图.A3将产生一个情节.
谢谢
在SCRIPT中,我能够初始化在工作空间中显示为空变量的变量:
mass = [];
speed = [];
velocity = [];
Run Code Online (Sandbox Code Playgroud)
但是当我将这些相同的初始化变量放在FUNCTION中时,MATLAB不会识别它们,也不会将它们存储在工作区中.
function myvariables()
mass = [];
speed = [];
velocity = [];
Run Code Online (Sandbox Code Playgroud)
如何在函数中执行初始化变量?
我试图确定字符串Apples出现在文本文件中的时间以及出现的行数.
脚本输出的行号不正确,而是连续输出数字(1,2,..),而不是单词的正确行.
Apples
Grapes
Oranges
Apples
Run Code Online (Sandbox Code Playgroud)
Apples appear 2 times in this file
Apples appear on these lines: 1, 4,
Run Code Online (Sandbox Code Playgroud)
相反,我的输出如下面的代码所示:
Apples appear 2 times in this file
Apples appear on these lines: 1, 2,
Run Code Online (Sandbox Code Playgroud)
my $filename = "<file.txt";
open( TEXT, $filename );
$initialLine = 10; ## holds the number of the line
$line = 0;
$counter = 0;
# holder for line numbers
@lineAry = ();
while ( $line = <TEXT> ) {
chomp( …Run Code Online (Sandbox Code Playgroud)