我已在MATLAB中的以下内容:的Bash脚本 - > While循环,For循环,如果声明(从MATLAB转换)
while ~feof(fi)
dline== fgetl(fi)
if count == 0
if dline == -1
<do stuff>
end
end
if dline(end-27) == ':'
dline = dline(1:end-28)
end
<output>
for i = 32:size(dline,2)
if dline(i) == '{'
count = count + 1
sp = []
for j = 1:count
sp = [sp;s]
end
<output>
elseif dline(i) == '}'
count = count - 1
sp = []
for j = 1:count
sp = [sp;s]
end
<output>
elseif dline(i) == ','
<output>
else
<output>
end
end
我有我的鼎联的索引麻烦。例如在MATLAB:
if dline(i) == '{'
翻译到外壳脚本,我有:
if [ ${line[i]} == '{' ]
或一些变体。但是我收到了与此相关的错误,或者找不到'{'。我试图用'$ x'替换'i',其中'x'从循环内的32开始计数。我尝试用“$ match1”取代'{',其中'$ match1'='{'。
请忽略MATLAB代码中的任何问题,我知道这很有效,而且我只是很快输入了它。我更感兴趣的是将该代码转换为可用的BASH脚本(在Linux上)。
那么,你真正的问题是什么......? – 2013-04-09 19:48:03
在你想测试的变量周围加上双引号,并删除其中一个'=' – michaelmeyer 2013-04-09 19:52:17