Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7597217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:06:19+00:00 2026-05-30T22:06:19+00:00

my current code is below. What I have is two sets of data phi

  • 0

my current code is below.

What I have is two sets of data phi and theta both 18×30 and I have a for loop running from 1 to 30 which are the 30 columns of my data. Each of these individual columns will produce a matrix ‘B’ for me. The matrix ‘B’ is produced after going through the 18 rows of each column.

The problem I have is that I need to multiply all the resulting ‘B’ matrices for each of the 18 rows with each other in order to get a final matrix for each of the 30 columns, that is why I have set A(:,:,i) = eye(2) so that my first matrix will multiply by A. But I don’t want to store A or B for each loop, instead what I want is that on the first loop of i my matrix B will multiply the identity matrix A. Then that matrix A will multiply the next matrix B…with the result of each multiplication being carried forward to the next matrix B that will be calculated, so the multiplications will get done as the program loops. That’s why I have the line:

A(:,:,i) = A.*B;

but it doesn’t seem to work. I get an error message saying the dimensions must match.

At the end of the program I want to be able to access each of the 30 matrices using a command like:
A(:,:,3), for example, to get my 2×2 matrix for the 3rd column.

Hope that was clear enough!

theta = dlmread('theta.dat');
phi = dlmread('phi.dat');

ne = 1.7;
no = 1.5;
d = 0.000001;
w = 0.000000555;

for i = 1:30
        A(:,:,i) = eye(2);

for j = 1:18    

    nx =((cos(theta(j,i)).^2)/(no^2) + ((sin(theta(j,i)).^2)/(ne^2))).^(-1/2);
    D = (2*pi*(nx-no)*d)/w;

    x = ((cos(phi(j,i))).^2).*exp((-1i.*D)/2) + ((sin(phi(j,i))).^2).*exp((1i.*D)/2);
    y = 1i*(sin(D/2)).*sin(2*phi(j,i));
    z = ((cos(phi(j,i))).^2).*exp((1i.*D/2) + ((sin(phi(j,i))).^2).*exp((-1i.*D)/2));

    B = [x y;y z];
    A(:,:,i) = A.*B;

end

end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:06:20+00:00Added an answer on May 30, 2026 at 10:06 pm

    B is a 2×2 matrix. For A.*B to work, A must also be 2×2. But A in your program is three-dimensional.

    From your problem description, I think you want

    A(:,:,i) = A(:,:,i)*B;  % Edited now that I see this happens 18 times on the same i
    

    (Please note, I also replaced element-wise multiply .* with matrix multiply *, because that’s what it sounds like you want.)


    But I suggest

    A = eye(2);
    

    and

    A = A*B;
    

    and store it at the end like

    results(:,:,i) = A;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model, Director with two DateFields, and two subclasses (code below). I
In the code below I have two Canvas layers one text and one image,
I have two sites running which share a membership provider. One of them is
My current code needs to read foreign characters from the web, currently my solution
I am having a bit of difficulty with this current code I have set
I have two colorbox popup boxes which show a YouTube video in each. When
In my current project, I have two models, Version and Comment. There is a
As far as I know, the code below gets a shape from the active
I have two identical servers. Both Win2k3. I have a web service that queues
I have this two strings of equal length, which I need to compare. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.