Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
迎接大家
我正在尝试根据 for 循环的长度多次将字符(括号) ')'输出到文件中。例子:
num1=23; for i=1 length(array) fprintf(fid,strcat(num2str(num1)),')') end
输出到文件将是23))))))
数组的长度是 6 它应该打印 6 括号))))))到文件
我在 linux 上使用 octave/matlab。
使用 repmat,例如:string = repmat(')',1,6)将生成))))))并将其存储在 variable 中string。然后您可以将此字符串附加fprintf到文件中。
string = repmat(')',1,6)
))))))
string
fprintf
string = repmat(')',1,6) fprintf(fid,[num2str(num1) string])
顺便说一句,matlab 中的字符串连接使用:str = ['str1' 'str2' 'str3']比 strcat 做得更好。
str = ['str1' 'str2' 'str3']