Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Multiple (1000s) iterations of a worksheet

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-08-2012
10:00 AM

08-08-2012
10:00 AM

Multiple (1000s) iterations of a worksheet

Hi Guys,

I'm new to MathCad and, like many, confronting the learning curve. I've inherited a model (~10pages) witten in M15 that spits out power consumption of my system for a given array of frequencies of input. I need to turn this into a recurrent calculation to see the power consumption over time. I've inserted a matlab script that calculates my inputs and it spits out a matrix of thousands of columns. I need to then calculate the power for each column and save it somewhere. All was dandy until I've found that loops can't incorporate references.

Any suggestions of how to structure this?

Many thanks in advance.

-Roger

Labels:

12 REPLIES 12

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-08-2012
11:16 AM

08-08-2012
11:16 AM

Re: Multiple (1000s) iterations of a worksheet

In principal, it shouldn't be a problem for Mathcad to calculate functions of column, but ...

Could you explain in more detail what you mean by "can't incorporate references" and why that is a problem? Can you post an example of what you mean? How many rows does your matrix have?

Stuart

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-08-2012
11:22 AM

08-08-2012
11:22 AM

Re: Multiple (1000s) iterations of a worksheet

Make the calculation of power a function of frequency array: power(frequencyarray):=....

Then write a loop that calls this function, passing it each column of the matlab constructed matrix through each pass, along the lines of:

p is then a vector of powers; one for each column of the Matlab matrix (assuming one value of power results from one column of the matrix).

Can you upload a simplified worksheet with just a few columns and a simplified power calculation so we can see exactly what your problem is?

Alan

Oops! In the function above, for 'rows' read 'cols'

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-08-2012
11:43 AM

08-08-2012
11:43 AM

Re: Multiple (1000s) iterations of a worksheet

So, if I understood corrctly, I should try and make my existing model (worksheet) a function. Then I can call the function and calculate the power. Correct?

Would that be like calling a function (.m file) in matlab? Can I just define a function at the start of the xmcd file?

The algorithm I have in mind for this is like so:

call matlab script to get frequency/ loudness of wav file (done)

- output is matrix of loudness per 100ms

- matrix has a column for each time sample

for each column of matrix

call power model (old file)

calculate power

save in power vector

save power vector and loudness matrix

plot vector

Does this help any?

It's the for loop I'm stuck on. The rest works =)

Ideally I would call the file (add as a reference?) and just let it spit out my power consumption. The model I have only calculates instantaneous power. So I have to loop it for all the time frames of my input file. I've attached one of the pages from my inherited model, as requested.

Edit:

The trial matrix I have is ~200,000 columns

Thanks for your guys's help!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-08-2012
11:56 AM

08-08-2012
11:56 AM

Re: Multiple (1000s) iterations of a worksheet

I'm having trouble relating your expaination at the top to your picture.What in the picture changes based on a time sample; your page looks to be self-contained without any external references.

Can you post a sheet with a short sample. (Advanced editor allows files to be attached.)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-08-2012
12:01 PM

08-08-2012
12:01 PM

Re: Multiple (1000s) iterations of a worksheet

Hi Fred,

So I agree, there are no external references. This is from the power calculation worksheet (6/10), I thought that is what was asked for.

As for a look at what I'm doing (trying to do) here's my worksheet so far (not sure this will help).

Tha gap in the for loop is where I was going to insert the reference to my other worksheet.

Thanks!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-08-2012
01:16 PM

08-08-2012
01:16 PM

Re: Multiple (1000s) iterations of a worksheet

I've added a few notes. WIthout data I can't do much, and I'm assuming that Ptot_app is a calculation on the data.

You cannot call a worksheet from inside another worksheet. Installing a reference to a worksheet is identical to pasting the contents of the worksheet in (just like copy all/paste.) If you have defined a function, it will execute; but I don't see any evidence that you know about functions.

If you show me what P tot_app does, I'll try to update this file.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-08-2012
03:13 PM

08-08-2012
03:13 PM

Re: Multiple (1000s) iterations of a worksheet

If you simply have a large matrix and wish to apply a function to each column, then the simplest thing to do is iterate through each column and use the column operator (ctl-6) to extract the data and then pass it to the function; then store the results in a vector (I presume you know that Mathcad uses column matrices to represent vectors and that the indexing base is 0 rather than Matlab's 1 ...). See attached for a generic example (the functions fillmat and randmat are defined in the collapsed Area named 'Utilities').

Stuart

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-08-2012
03:16 PM

08-08-2012
03:16 PM

Re: Multiple (1000s) iterations of a worksheet

Ah ... stable door ... horse ... bolt

Ignore the above post - I've just noticed that Alan has already said the same thing.

Stuart

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-09-2012
02:47 AM

08-09-2012
02:47 AM

Re: Multiple (1000s) iterations of a worksheet

Structure should be more like the attached.

Alan

PS In Mathcad functions are usually defined *before* they are called, compared with Matlab's requirement to define them after the calling program.

Top Tags