Need Help with fixing "Error using vertcat Dimensions of matrices being concatenated are not consistent" for my matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello All,
I am in need of some help, I am trying to store results where P1, P2, and P3 are dependent on J in matrix B however I keep getting the the vertcat error message. I believe it may have something to do with storing several matrices in one matrix but I don't really know how to get around this since I need to create a matrix for every value of J.
j = 0:10;
B = [0;(P1+P2+P3);(P1+P2+P3);P1;0;0;0;0;0;P3;0;P2];
Any help would be appreciated!
Thank you for your time.
CAAJ
0 Kommentare
Akzeptierte Antwort
John BG
am 10 Feb. 2017
another way would be (let me call j now j0)
syms j0
P2(j0)=3*j0^2-2*j0+.5
P2(j0) =
3*j0^2 - 2*j0 + 1/2
>> P3(j0)=(8-j0^2).^5
P3(j0) =
-(j0^2 - 8)^5
B = [0;(P1+P2+P3);(P1+P2+P3);P1;0;0;0;0;0;P3;0;P2]
B(j0) =
0
3*j0^2 - (j0^2 - 8)^5 - j0 + 3/2
3*j0^2 - (j0^2 - 8)^5 - j0 + 3/2
j0 + 1
0
0
0
0
0
-(j0^2 - 8)^5
0
3*j0^2 - 2*j0 + 1/2
now you change j0 from symbolic to double
j0=[0:1:10]
=
0 1 2 3 4 5 6 7 8 9 10
and translate symbolic B to a cell
C=sym2cell(B)
you can still read the symbolic expression with
C{1}
ans(j0) =
0
3*j0^2 - (j0^2 - 8)^5 - j0 + 3/2
3*j0^2 - (j0^2 - 8)^5 - j0 + 3/2
j0 + 1
0
0
0
0
0
-(j0^2 - 8)^5
0
3*j0^2 - 2*j0 + 1/2
but you have all numeric values, individually
single(C{1}(4))
ans =
1.0e+04 *
0
-3.2722500
-3.2722500
0.0005000
0
0
0
0
0
-3.2768000
0
0.0040500
or read all values to for instance write them in another variable
for k=1:1:numel(j0)
double(C{1}(k))
end
=
1.0e+04 *
0
1.681050000000000
1.681050000000000
0.000200000000000
0
0
0
0
0
1.680700000000000
0
0.000150000000000
=
1.0e+03 *
0
1.035500000000000
1.035500000000000
0.003000000000000
0
0
0
0
0
1.024000000000000
0
0.008500000000000
..
=
1.0e+10 *
0
-1.842435143950000
-1.842435143950000
0.000000001200000
0
0
0
0
0
-1.842435179300000
0
0.000000034150000
if you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG
0 Kommentare
Weitere Antworten (2)
James Tursa
am 10 Feb. 2017
Not sure what P1, P2, and P3 dimensions are, but maybe something like this is what you need:
row0 = zeros(1,size(P1,2));
B = [row0;(P1+P2+P3);(P1+P2+P3);P1;row0;row0;row0;row0;row0;P3;row0;P2];
7 Kommentare
James Tursa
am 10 Feb. 2017
Display in what way? For one thing, your j variable has 11 elements, but your B variable has 12 rows. So not sure how they correlate to each other.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!