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

  • SEARCH
  • Home
  • 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 8261565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:27:15+00:00 2026-06-08T03:27:15+00:00

I have the following two vector fields: >> orient orient = [1×3 double] [1×3

  • 0

I have the following two vector fields:

>> orient

orient = 

    [1x3 double]    [1x3 double]    [1x3 double]
    [1x3 double]    [1x3 double]    [1x3 double]
    [1x3 double]    [1x3 double]    [1x3 double]

>> distance

distance = 

    [1x3 double]    [1x3 double]    [1x3 double]
    [1x3 double]    [1x3 double]    [1x3 double]
    [1x3 double]    [1x3 double]    [1x3 double]

and I need to take the cross product of pairwise elements i.e.

b = (cross(orient{1,1},distance{1,1}) + cross(orient{1,2},distance{1,2})..... and so on

and then reshape to match the dimensions of distance and orient.

Can I do this without using a for loop?

and what about if I have

orient{1,1} = 

[1x3 double]

distance = 

        [1x3 double]    [1x3 double]    [1x3 double]
        [1x3 double]    [1x3 double]    [1x3 double]
        [1x3 double]    [1x3 double]    [1x3 double]

how do I do

sum1 = (cross(orient{1,1},distance{1,1}) + cross(orient{1,1},distance{1,2}) +…)
sum2 = (cross(orient{1,2},distance{1,1}) + cross(orient{1,2},distance{1,2}) +…)

where each ‘sum’ is just an iteration of a single orient element, crossed with all the elements of distance, and then those cross products are summed. I would then have:

mastersum = sum1 sum2 sum3
            sum4 sum5 sum6
            sum6 sum8 sum9

where

sum1 = 

[1x3 double]

Am I just putting this in a confusing way?

  • 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-06-08T03:27:16+00:00Added an answer on June 8, 2026 at 3:27 am

    You’ll need to use cellfun to traverse the cell arrays without a for-loop.

    For two vector fields (two cell arrays), you should do:

    crosses = cellfun(@(u, v)cross(u, v)', orient, distance, 'UniformOutput', 0);
    b = sum(cell2mat({crosses{:}})', 1)  %# Summing all vectors in all cells
    

    A similar procedure for single cell from orient, say orient{1, 2}, would be:

    u = orient{1, 2};
    crosses = cellfun(@(v)cross(u, v)', distance, 'UniformOutput', 0);
    b = sum(cell2mat({crosses{:}})', 1)  %# This command remains the same
    

    To get the result for all vectors from orient without a for loop, do instead:

    b_func = @(u)sum(cell2mat(cellfun(@(v)cross(u,v)', {distance{:}}, 'Un', 0))', 1);
    U = cellfun(b_func, orient, 'UniformOutput', 0)
    

    Now U is also a cell array (of the same dimensions as orient): U{1, 1} has the sum of crosses for orient{1, 1}, U{1, 2} for orient{1, 2}, and so on…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
I have the following two boost::fusion maps. namespace bf = boost::fusion; typedef bf::map<bf::pair<char,float>,bf::pair<int,double>> FusionMap;
I have the following code that I use to compute the distance between two
I have two struct s defined as in the following: struct vertex { double
I have the following two Vector objects in java. Vector<SomeClass> obj1; Vector<SomeClass> obj2; The
I have defined two dimensional array using following definition typedef std::vector<std::vector<short> > table_t; Can
I have the following code which forks two new processes to take the contents
I'd like to do the following. but don't know how: //have two vectors: vector1
I have following two arrays. I want the difference between these two arrays. That
How to wrap one div around another? I have following two div ids: #course

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.