Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Dimension mismatch when concatenating arrays? Ideas?

Subject: Dimension mismatch when concatenating arrays? Ideas?

From: Jen

Date: 3 Mar, 2013 19:44:09

Message: 1 of 2

Hi all,

I have a code in which I am trying to concatenate two different vectors horizontally with a different number of rows, so I'm getting a dimension mismatch error. My problem is that I'm not sure logically how to remedy this ... any ideas?

Thanks!

 method = 'Dehydriding';
    switch method
        case 'Dehydriding'
           
            count = 1;
            count_2 = 1;
            count_3 = 1;
            c = size(append);
           
            while 1
            for k = 2:c(2)
                if isempty(append(count,k).off)==1
                    break;
                end
                append(count,k).off = append(count,k).off-append(count,k).off(1)...
                    +append(count,k-1).off(length(append(count,k-1).off));
                time(count,k).off = time(count,k).off-time(count,k).off(1)...
                    +time(count,k-1).off(length(time(count,k-1).off));
            end
            
            P_dehydriding(:,count_2) = vertcat(append(count,:).off);%<-Length is different for each count
            t_dehydriding(:,count_2) = vertcat(time(count,:).off);%<-Here too
            count_2=count_2+1;
            count=count+1;
            for k = 3:c(2)
                if isempty(append(count,k).off)==1
                    break;
                end
                append(count,k).off = append(count,k).off-(append(count,k).off(1)...
                    -append(count,k-1).off(length(append(count,k-1).off)));
                time(count,k).off = time(count,k).off-(time(count,k).off(1)...
                    -time(count,k-1).off(length(time(count,k-1).off)));
            end
            P_hydriding(:,count_3) = vertcat(append(count,:).off);
            t_hydriding(:,count_3) = vertcat(time(count,:).off);
            count_3 = count_3+1;
             count=count+1;
                if count>c(1)
                    break;
                end
            end

Subject: Dimension mismatch when concatenating arrays? Ideas?

From: anyone

Date: 4 Mar, 2013 01:32:06

Message: 2 of 2

On Sun, 03 Mar 2013 19:44:09 +0000, Jen wrote:

> Hi all,
>
> I have a code in which I am trying to concatenate two different vectors
> horizontally with a different number of rows, so I'm getting a dimension
> mismatch error. My problem is that I'm not sure logically how to remedy
> this ... any ideas?

Help -> reshape

If that won't do it, try adding rows/columns of NANs as placeholders to match dimensions; concatenate; remove/
ignore NANs.

> Thanks!

For what?

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us