char combining error: Matrix dimensions must agree. - SIMPLE SCRIPT

7 ビュー (過去 30 日間)
Fabrizio Argentieri
Fabrizio Argentieri 2019 年 1 月 4 日
コメント済み: Stephen23 2019 年 1 月 4 日
I am importing a large quantity of .dat files. I get this error even when running an apparently simple code:
clear all
clc
n='20000'
u='u2DSolution'+n+'.dat'
Error:
Matrix dimensions must agree.
Error in Untitled (line 5)
u='u2DSolution'+n+'.dat'
  1 件のコメント
Stephen23
Stephen23 2019 年 1 月 4 日
"I get this error even when running an apparently simple code:"
It is simple code: you are adding the character codes of some character vectors. Just like with numeric vectors if they have incompatible sizes then you will get an error.
You probably want to concatenate those character vectors, rather than add their chracter codes.

サインインしてコメントする。

回答 (2 件)

Steven Lord
Steven Lord 2019 年 1 月 4 日
The + operator performs concatenation if one of the things you're "adding" together is a string array.
n = 20000;
u = "u2DSolution" + n + ".dat"
The + operator when called with char arrays (no string arrays involved) performs arithmetic if the inputs are compatibly sized.
b = 'a' + 1 % double('b') which you can check with
characterB = char(b)

madhan ravi
madhan ravi 2019 年 1 月 4 日
n='20000'
u=['u2DSolution',n,'.dat']

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by