필터 지우기
필터 지우기

Converting cell 2 matrix get an error if the numbers don't have the same number of digits, why?

조회 수: 2 (최근 30일)
I havea table on gui and fill 2 number 12500 and 12600 and saved as cell. When I convert it to matrix using cell2mat, if the two numbers don't have the same numebr of digits (12500 and 1250 for example) I get this error "Error using cat Dimensions of matrices being concatenated are not consistent.
Error in cell2mat (line 83) m{n} = cat(1,c{:,n});
Error in main3>pushbutton15_Callback (line 235) matbuildcost=cell2mat(buildcost)"
How should I do?
Thank you

채택된 답변

Stephen23
Stephen23 2015년 7월 16일
편집: Stephen23 2015년 7월 16일
Because that cell array actually contains strings, and does not contain numeric values. If the strings are of different lengths then they cannot be concatenated together vertically, thus the error. The easiest solution is to convert the strings to numeric values using str2double. If you want to keep the data in string form, then use char instead.
Lets have a look at an example:
>> X = {'12500';'1250'};
>> cell2mat(X)
Error using cat
Dimensions of matrices being concatenated are not consistent.
Error in cell2mat (line 84)
m{n} = cat(1,c{:,n});
>> str2double(X)
ans =
12500
1250
  댓글 수: 3
Stephen23
Stephen23 2015년 7월 17일
Please show exactly how you are generating your data, and upload the data in a .mat file.
Kelly Kyriakou
Kelly Kyriakou 2015년 7월 17일
I have the following table where the user fill it. Columns X,y and Roadid get filled automatically when user press a save button getting data from data cursor tool as it is shown on map. I uplooaded an m. file where there is the code that save data, assign them to variables and set these data visible on the table. However, in order to run it it is needed fig file. Shall I upload it too?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by