Hello Matlab community !
I am working on kinematics for a 3DOF finger. I recently made a small program which moves the finger from one spot to another.For example from spot A(x1,y1) to B(x2,y2).
The problem i have with the program is that if x1=x2 or y1=y2 I get an error which says «
«??? Error using ==> horzcat
CAT arguments dimensions are not consistent.
Error in ==> move at 72
C=[ones(size(B))*A1,A2] «
This is the program i have made.
————————————————————
function move(X1,Y1,X2,Y2,phi)
l1=3.9;
l2=6.2;
l3=4.7;
GB=abs(X1-X2);
AG=abs(Y1-Y2);
and GB=X=|X1-X2|
B=20;
if X1>X2;
A1=Linspace(X1,X2,B);
elseif X1<X2;
A1=Linspace(X1,X2,B);
else
A1=[ones(size(B))*X1];
end
A1=A1′
if Y1>Y2;
A2=Linspace(Y1,Y2,B);
elseif Y1<Y2;
A2=Linspace(Y1,Y2,B);
else
A2=[ones(size(B))*Y1];
end
A2=A2′
C=[ones(size(B))*A1,A2]
i=1;
for i=1:B
Px=C((i),1);
Py=C((i),2);
phi=phi*pi/180;
sigma=(Px^2+Py^2+l3^2-l1^2-l2^2-2*l3*(Px*cos(phi)+Py*sin(phi)))/2/l1/l2;
Q2=atan2(+sqrt(1-sigma^2),sigma);
num1=(Py-l3*sin(phi)) * (l1+l2*cos(Q2)) — (Px-l3*cos(phi))*l2*sin(Q2);
den=(l1^2+l2^2+2*l1*l2*cos(Q2));
num2=(Px-l3*cos(phi))*(l1+l2*cos(Q2))+(Py-l3*sin(phi))*l2*sin(Q2);
Q1=atan2(num1/den,num2/den);
Q3=phi-Q1-Q2;
Q1=Q1*180/pi;
Q2=Q2*180/pi;
Q3=Q3*180/pi;
Q((i),1)=Q1;
Q((i),2)=Q2;
end
grid on
j=1;
for j=1:B,
q1=Q((j),1);
q2=Q((j),2);
q3=Q((j),3);
q1=q1*pi/180;
q2=q2*pi/180;
q3=q3*pi/180;
x=l1*cos(q1)+l2*cos(q1+q2)+l3*cos(q1+q2+q3);
y=l1*sin(q1)+l2*sin(q1+q2)+l3*sin(q1+q2+q3);
f=q1+q2+q3;
x1=l1*cos(q1);
x2=l1*cos(q1)+l2*cos(q1+q2);
y1=l1*sin(q1);
y2=l1*sin(q1)+l2*sin(q1+q2);
line( [0 x1 x2 x], [0 y1 y2 y], [ 0 0 0 0 ])
hold on
plot(0,0,‘o’)
plot(x1,y1,‘o’)
plot(x2,y2,‘o’)
plot(x,y,‘o’,‘LineWidth’,30)
AXIS([-3 15.13 -3 15.13])
pause(0.2)
end
end
Thanks a lot in advance !
Accepted Answer
When x1=x2 but y1~=y2, your A1 is a scalar but A2 is a column vector, hence it cannot be concatenated. Similar thing for x1~=x2 but y1=y2. But you should be able to easily figure this out if you simply put a breakpoint at the error out line and test the dimension of A1 and A2.
More Answers (0)
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Dear all,
Using the next function, I get the error mentioned:
function [Y]=descriptiveStats( X )
M={};
N=[];
M={‘mean’,‘sem’,‘numel’,‘std’,‘var’,‘min’,‘max’}.’;
[mean,sem,numel,std,var,min,max]=grpstats(X,[],{‘mean’,‘sem’,‘numel’,‘std’,‘var’,‘min’,‘max’});
N=[mean,sem,numel,std,var,min,max].’;
Y=[M,N];
xlswrite(‘df.xlsx’,Y)
end
The results displayed in the command window look like this:
>> dFStats = descriptiveStats(decodeFemale);
size(M)
7 1
size(N)
7 1
M
‘mean’
‘sem’
‘numel’
‘std’
‘var’
‘min’
‘max’
N
1.7802
0.0935
186.0000
1.2749
1.6254
0
4.7137
Error using horzcat
CAT arguments dimensions are not consistent.
Error in descriptiveStats (line 20)
Y=[M,N];
However, if I use an additional argument gname that displays a character I don’t get the aforementioned error:
function [Y]=descriptiveStats( X )
M={};
N=[];
M={‘mean’,‘sem’,‘numel’,‘gname’,‘std’,‘var’,‘min’,‘max’}.’;
[mean,sem,numel,gname,std,var,min,max]=grpstats(X,[],{‘mean’,‘sem’,‘numel’,‘gname’,‘std’,‘var’,‘min’,‘max’});
N=[mean,sem,numel,gname,std,var,min,max].’;
Y=[M,N];
xlswrite(‘df.xlsx’,Y)
end
And this are the results printed in the command window:
>> dFStats = descriptiveStats(decodeFemale);
size(M)
8 1
size(N)
8 1
M
‘mean’
‘sem’
‘numel’
‘gname’
‘std’
‘var’
‘min’
‘max’
N
[1.7802]
[0.0935]
[ 186]
‘1’
[1.2749]
[1.6254]
[ 0]
[4.7137]
It’s not a big deal to have to use the gname argument in order to avoid the error, but I don’t understand why it is happening.
Can somebody explain what’s the cause and how to fix it?
Regards,
Diego
Accepted Answer
Easy. Without the gname argument, what is being returned is a simple 7 x 1 numeric array, which would occupy at most one cell entry rather than the 7 you would need in order to match the 7 x 1 cell array of strings you constructed in M. But when you use gname, it needs to return a string as part of the output and so cannot just return a numeric array, so it returns a cell array of the right size for you to match with M.
Solution:
More Answers (2)
Check the data type of N in both cases.
I have the same problem with horzcat. I tried num2cell. But, it is not working. Can anybody help me.
clc
clear all
filename = ‘testdata.xlsx’;
timeVariable=ones(1,10)
timeVariable = timeVariable’
tempVariable = 10*rand(1,10)
tempVariable = tempVariable’
a = horzcat(timeVariable, tempVariable);
A = {‘Time’,‘Temperature’; [timeVariable, tempVariable]};
sheet = 1;
xlRange = ‘E1’;
xlswrite(filename,A,sheet,xlRange)
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Содержание
- Error using horzcat Dimensions of arrays being concatenated are not consistent.
- Direct link to this question
- Direct link to this question
- Accepted Answer
- Direct link to this answer
- Direct link to this answer
- More Answers (0)
- See Also
- Categories
- Products
- Release
- Community Treasure Hunt
- How to Get Best Site Performance
- Americas
- Europe
- Asia Pacific
- Error using horzcat Dimensions of matrices being concatenated are not consistent.
- Direct link to this question
- Direct link to this question
- Accepted Answer
- Direct link to this answer
- Direct link to this answer
- Direct link to this comment
- Direct link to this comment
- More Answers (0)
- See Also
- Categories
- Community Treasure Hunt
- How to Get Best Site Performance
- Americas
- Europe
- Asia Pacific
- Error using horzcat Dimensions of matrices being concatenated are not consistent
- Direct link to this question
- Direct link to this question
- Direct link to this comment
- Direct link to this comment
- Answers (0)
- See Also
- Categories
- Products
- Community Treasure Hunt
- How to Get Best Site Performance
- Americas
- Europe
- Asia Pacific
- Error using horzcat — CAT arguments dimensions are not consistent.
- Direct link to this question
- Direct link to this question
- Answers (1)
- Direct link to this answer
- Direct link to this answer
- Direct link to this comment
- Direct link to this comment
- See Also
- Categories
- Products
- Community Treasure Hunt
- How to Get Best Site Performance
- Americas
- Europe
- Asia Pacific
- Error using horzcat CAT arguments dimensions are not consistent
- Direct link to this question
- Direct link to this question
- Direct link to this comment
- Direct link to this comment
- Answers (0)
- See Also
- Categories
- Community Treasure Hunt
- How to Get Best Site Performance
- Americas
- Europe
- Asia Pacific
Error using horzcat Dimensions of arrays being concatenated are not consistent.
Direct link to this question
Direct link to this question
0 Comments
Accepted Answer
Direct link to this answer
Direct link to this answer
0 Comments
More Answers (0)
See Also
Categories
Products
Release
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Читайте также: Rom manager ошибка загрузки
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 简体中文 Chinese
- English
- 日本 Japanese (日本語)
- 한국 Korean (한국어)
Accelerating the pace of engineering and science
MathWorks is the leading developer of mathematical computing software for engineers and scientists.
Источник
Error using horzcat Dimensions of matrices being concatenated are not consistent.
Direct link to this question
Direct link to this question
0 Comments
Accepted Answer
Direct link to this answer
Direct link to this answer
1 Comment
Direct link to this comment
Direct link to this comment
More Answers (0)
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 简体中文 Chinese
- English
- 日本 Japanese (日本語)
- 한국 Korean (한국어)
Читайте также: Eof on socket error
Accelerating the pace of engineering and science
MathWorks is the leading developer of mathematical computing software for engineers and scientists.
Источник
Error using horzcat Dimensions of matrices being concatenated are not consistent
Direct link to this question
Direct link to this question
1 Comment
Direct link to this comment
Direct link to this comment
Answers (0)
See Also
Categories
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 简体中文 Chinese
- English
- 日本 Japanese (日本語)
- 한국 Korean (한국어)
Accelerating the pace of engineering and science
MathWorks is the leading developer of mathematical computing software for engineers and scientists.
Источник
Error using horzcat — CAT arguments dimensions are not consistent.
Direct link to this question
Direct link to this question
0 Comments
Answers (1)
Direct link to this answer
Direct link to this answer
1 Comment
Direct link to this comment
Direct link to this comment
See Also
Categories
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
Читайте также: Samsung galaxy on7 prime прошивка
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 简体中文 Chinese
- English
- 日本 Japanese (日本語)
- 한국 Korean (한국어)
Accelerating the pace of engineering and science
MathWorks is the leading developer of mathematical computing software for engineers and scientists.
Источник
Error using horzcat CAT arguments dimensions are not consistent
Direct link to this question
Direct link to this question
1 Comment
Direct link to this comment
Direct link to this comment
Answers (0)
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 简体中文 Chinese
- English
- 日本 Japanese (日本語)
- 한국 Korean (한국어)
Accelerating the pace of engineering and science
MathWorks is the leading developer of mathematical computing software for engineers and scientists.
Источник
-
malike
- Пользователь
- Сообщения: 8
- Зарегистрирован: Вт мар 12, 2013 11:59 am
!!!HELP!!!Подскажите красивое решение!
Есть некоторое колличество текстовых файлов, в них записаны данные в формате
yyyy.MM.dd (DDD) HH:mm:ss foF2
2012.07.01 (183) 00:00:00 4.960
Подскажите,Какой функцией можно преобразовать их в массив, чтобы строить график для функции foF2???
-
kronos13
- Пользователь
- Сообщения: 38
- Зарегистрирован: Ср ноя 10, 2010 9:01 am
Сообщение kronos13 » Пт мар 15, 2013 11:34 am
Перенесите файл мышкой в workspace, появиться окно импорта, настройте как надо, поставьте галочку генерировать m-файл и если все устраивает, то используйте полученный файл функции.
-
abobroff
- Пользователь
- Сообщения: 488
- Зарегистрирован: Пн окт 25, 2010 1:21 pm
Сообщение abobroff » Пт мар 15, 2013 2:07 pm
Код: Выделить всё
f = fopen('your_file.txt');
c = textscan(f,'%s (%f) %s %f','HeaderLines',1);
fclose(f);
out = [datenum(strcat(c{1},'_',c{3}),'yyyy.mm.dd_HH:MM:SS') c{2} c{4}];
-
malike
- Пользователь
- Сообщения: 8
- Зарегистрирован: Вт мар 12, 2013 11:59 am
Сообщение malike » Вт мар 19, 2013 6:14 pm
Пробую запускать ваш код. Получаю только ошибки. Может что-то не так делаю? Как встроить сюда выбор файла методом мультиселекта?
-
malike
- Пользователь
- Сообщения: 8
- Зарегистрирован: Вт мар 12, 2013 11:59 am
Сообщение malike » Вт мар 19, 2013 10:12 pm
Вот что вываливает Матлаб на попытку запустить код:
«Error using horzcat
CAT arguments dimensions are not consistent.
Error in NEW (line 16)
out = [datenum(strcat(c{1},’_’,c{3}),’yyyy.mm.dd_HH:MM:SS’) c{2} c{4}]; »
В чем ошибка?
Код: Выделить всё
f = fopen('DB049_20120701(183).txt');
c = textscan(f,'%s (%f) %s %f','HeaderLines',1);
fclose(f);
out = [datenum(strcat(c{1},'_',c{3}),'yyyy.mm.dd_HH:MM:SS') c{2} c{4}];
-
Сергей aka Грифон
- Пользователь
- Сообщения: 857
- Зарегистрирован: Вс ноя 22, 2009 4:24 pm
Сообщение Сергей aka Грифон » Вт мар 19, 2013 11:17 pm
часть объединяемых векторов является строками, а часть столбцами. Проверьте входные данные.
При наличии доступа к гуглу студент обязан быть богоподобен
-
malike
- Пользователь
- Сообщения: 8
- Зарегистрирован: Вт мар 12, 2013 11:59 am
Сообщение malike » Ср мар 20, 2013 9:15 pm
Проверить на предмет чего? Формат данных во всех файлах одинаков!
It looks to me from reading the help on Matlab’s Kruskal Wallis test as if it would be easy to stack up your different responses and have an indicator for group, using the kruskalwallis(x,group)
syntax.
You ask about doing it in R in comments.
Here’s the first example from the R help on kruskal.test
, done first using three groups placed into a list, and the second way by stacking them and constructing a group variable:
> x <- c(2.9, 3.0, 2.5, 2.6, 3.2) # normal subjects
> y <- c(3.8, 2.7, 4.0, 2.4) # with obstructive airway disease
> z <- c(2.8, 3.4, 3.7, 2.2, 2.0) # with asbestosis
> kruskal.test(list(x, y, z))
Kruskal-Wallis rank sum test
data: list(x, y, z)
Kruskal-Wallis chi-squared = 0.7714, df = 2, p-value = 0.68
> ## Equivalently,
> x <- c(x, y, z)
> g <- factor(rep(1:3, c(5, 4, 5)),
+ labels = c("Normal subjects",
+ "Subjects with obstructive airway disease",
+ "Subjects with asbestosis"))
> kruskal.test(x, g)
Kruskal-Wallis rank sum test
data: x and g
Kruskal-Wallis chi-squared = 0.7714, df = 2, p-value = 0.68
Then there’s the formula interface:
> kruskal.test(x~g)
Kruskal-Wallis rank sum test
data: x by g
Kruskal-Wallis chi-squared = 0.7714, df = 2, p-value = 0.68
Now for random data without names (sample sizes 30 and 10):
> kruskal.test(list(rgamma(30,4,.1),rgamma(10,4,.2)))
Kruskal-Wallis rank sum test
data: list(rgamma(30, 4, 0.1), rgamma(10, 4, 0.2))
Kruskal-Wallis chi-squared = 4.3795, df = 1, p-value = 0.03637
Now for a whole bunch of different-sized groups:
> kruskal.test(list(rgamma(30,4,.1),rgamma(10,4,.2),rgamma(5,4,.3),
rgamma(6,4,.25),rgamma(8,4,.28)))
Kruskal-Wallis rank sum test
data: list(rgamma(30, 4, 0.1), rgamma(10, 4, 0.2), rgamma(5, 4, 0.3),
rgamma(6, 4, 0.25), rgamma(8, 4, 0.28))
Kruskal-Wallis chi-squared = 16.8088, df = 4, p-value = 0.002105
—
I’m sorry I seem to have missed the question inside this comment before: «How does R deal with empty values?» — you seem to be assuming the values will be stored in a rectangular array and since the groups are of different size, there will be missing values. Do I have that right?
Well, two issues:
1) R has the data value NA
to represent missing values. It is of any type (or rather, there’s one of each type).
e.g.:
x <- c(2.9, 3.0, 2.5, 2.6, 3.2)
y <- c(3.8, 2.7, 4.0, NA, 2.4)
cbind(x,y)
produces:
x y
[1,] 2.9 3.8
[2,] 3.0 2.7
[3,] 2.5 4.0
[4,] 2.6 NA
[5,] 3.2 2.4
2) R has data structures suited to non-rectangular data (like lists) that will allow you to avoid this problem in any case. For example, depending on what you’re trying to do, you could read each row into a vector and put those vectors into a list; the differences in length wouldn’t matter. They could then be handled with any of the above methods.
—
R can read in a variety of formats and a variety of ways of indicating missing values, or it can do formatted reads (and so identify them that way), so your ascii files should present no problems. It’s relatively straightforward.
Or, if you already have your data in matlab, the R.matlab
package should help.
Personally I’d just go with reading the data in. If you have something more complex than the usual sort of thing (covered in the help on read.table
and variants or scan
) you can always look at the relevant manual.
If you can show the kind of format of your files I may be able to give more detailed help.
Note that there are various documents for matlab or octave users to help them with R.