Why do I get an error within matlab(octave) using the vpi package using rdivide, mrdivide or quotient? - matlab

I am using octave for private use(I'm a student and there is unfortunately no free version of Matlab for students at my university)
Now I try to implement an algorithm using big numbers; So I started downloading the vpi package here:
http://www.mathworks.com/matlabcentral/fileexchange/22725-variable-precision-integer-arithmetic
Now I put the data in the right place and started working with it which was really great;
So I started for example with:
a=vpi(12989487973402)
a =
12989487973402
and then
a=a^10
a = 1367477916402329222848766554412698316550418920659968300260110320792
46979577273468682364762841107165766713454228653820366806955009024
which works really awesome; However I try now to use one of the commands rdivide, mrdivide or quotient of this package which is actually made for vpi numbers and should actually work; However it doesn't work with bigger numbers:
E.g.
b=vpi(129892);
c=b^2
c =
2191528947700288
rdivide(c,2)
ans =
1095764473850144
However when the numbers only a little bigger, I suddenly get error messages (with functions rdivide, mrdivide and quotient exactly the same ones)
c=b^4
c =
284662078074685808896
rdivide(c,2)
error: 'iszero' undefined near line 49 column 6
error: called from:
error: /home/john/test/#vpi/times.m at line 55, column 3
error: /home/john/test/#vpi/mtimes.m at line 27, column 7
error: evaluating argument list element number 1
error: /home/john/test/#vpi/quotient.m at line 103, column 9
>>>error: /home/john/test/#vpi/rdivide.m at line 43, column 5
Now I'm wondering if it is a problem of Octave and I need to have the original matlab or if it is a bug in the program or if I'm too stupid to use it???
Can someone help??? Thank you
EDIT: rdivide, mrdivide and quotient are working all very similar and they are supposed to return a./b for rdive/mrdivide/quotient(a,b) if a is divisible by b

Related

Error during rm ANOVA (Matlab) with random factor

I am trying to run a repeated measures ANOVA in Matlab with 4 factors including one factor representing my subjects which I want as a random factor.
The code I have is as follows:
[p,table,stats] = anovan(COORDS_SUBJ_II,{group_hand,group_stim,group_time,group_subs},'random',4,'varnames',{'HAND','STIM','TIME','SUBS'});
Here, all variables have the same dimension, which is 1350x1(all types are 'double'). I checked my code with some proposed code on the net and it matches, yet I keep getting the following error...
Error using chi2inv (line 3)
P and V must be of common size or scalars
Error in anovan>varcompest (line 838)
L = msTerm .* dfTerm ./ chi2inv(1-alpha/2,dfTerm);
Error in anovan>getRandomInfo (line 811)
[varest,varci] = varcompest(ems,randomterms,msTerm,dfTerm,alpha);
Error in anovan (line 296)
getRandomInfo(msterm,dfterm,mse,dfe,emsMat,randomterm,...
My dependent variable (COORDS_SUBJ_II) has a couple of NaN's in it, although I ran the code once where I replaced those NaN's with random numbers and it still gives me the same error. I am kind of lost right now and would appreciate any help.
Best
ty
Found it out. A toolbox I downloaded a while ago also had the chi2inv command and this prompted the error =)

MATLAB error(abcdchk(a,b,c,d)); What does this mean?

What does the code
error(abcdchk(a,b,c,d));
in MATLAB do? I'm trying to run a MATLAB script with this code snippet in Octave and getting
error: 'abcdchk' undefined near line 57 column 7
error: evaluating argument list element number 1
How can I fix this?
There appear to be multiple versions of the abcdchk() function out there (kind of depends on where you got the code from), for example this one from caltech and this one from Georgia Tech, but they all seem to check that the dimensions of the given matrices are consistent.

Looping over a Matlab structure

I am currently processing a bunch of files that I have imported into a structure, but have hit a bump in the road while trying to loop over the data.
First of all, here is my structure:
Ice
1.1 az160, az240, az300...
1.1.2 zen15, zen30,zen45...
1.1.2.1 Data
1.1.2.2 Textdata
I am trying to extract a value from each "textdata" cell array and use it to divide a column in data of the same structure. To do so, I am looping through the structure in the following way:
az_names = fieldnames(ice)
for m = 1:numel(az_names)
snames = fieldnames(ice.(az_names{m}))
for k = 1:numel(snames)
inttime = strrep(ice.(az_names{m}).(snames{k}).textdata(9,1), 'Integration > Time (usec): ','');
inttime = strrep(inttime, ' (USB2+E00040)','');
integration = cellfun(#str2num,inttime)
line 17 ice.(az_names{m}).(snames{k}).data(:,4) = ice.(az_names{m}).(snames{k}).data(:,3)/integration
end
end
I get the following error:
Index exceeds matrix dimensions
Edit: Matlab gives me the error at line 17. If I run the code up to "integration" and also write:
ice.(az_names{m}).(snames{k}).data(:,4)
I don't get a problem, Matlab prints to screen the right number and the data column.
I thought this would loop through each field in the structure and do the operation (dividing a column of values by a number), but I seem to be missing a point here. Can anybody see my mistake?
Regards,
If the error occurs when you try to execute this fragment:
ice.(az_names{m}).(snames{k}).data(:,4)
Then the cause is quite simple.
The variables m and k seem to be handled properly (due to the numel in the loop they should never be too big), meaning that the 4 is simply too big.
Check
ice.(az_names{m}).(snames{k}).data(:,4)
Or even more directly
size(ice.(az_names{m}).(snames{k}).data)
And you should find that the second element of the size is less than 4.
On second thought, this fragment works:
a.b=1;
a.b(:,4)=1
So I suspect that the error occurs when trying to read in this part:
ice.(az_names{m}). (snames{k}).data(:,3)
Meaning that the second element of the size should even be less than 3.
Also I would recommend removing the space.

Using GraphViz in MATLAB

I tried to plot graphs on MATLAB using GraphViz, using this GraphViz interface.
I keep getting this error:
>> [x,y]=draw_dot(G)
??? Attempted to access node_pos(2); index out of bounds because numel(node_pos)=1.
Error in ==> dot_to_graph at 94
y(lst_node) = node_pos(2);
Error in ==> draw_dot at 30
[trash, names, x, y] = dot_to_graph(tmpLAYOUT); % load NEATO layout
Whats really bugging me is that it worked great before (on my old computer).
Any idea how to solve this problem?
After debugging, I find the solution.
Just find the line 92 in dot_to_graph.m, as written:
[node_pos] = sscanf(line(pos_pos:length(line)), ' pos = "%d,%d"')';
Change the %d,%d to %f,%f. Because there are float numbers in the dot file.
This is difficult to answer completely since you are not giving us the G you are using, so we can't reproduce your problem directly; I'll attempt to answer anyhow "on the dry":
The error messages you get mean that the temporary DOT files created by neato in draw_dot can not be read properly; a line in the dot file which is parsed by dot_to_graph using the format string pos = "%d,%d" is expected to contain two numbers, e.g pos ="42,3", but MATLAB's sscanf only reads one number from that line.
Is it possible that your new computer uses a different language setting, i.e. using a decimal comma instead of a decimal point? This might cause Matlab to read the two numbers as one, not sure how sscanf adapts to local decimal point settings.
Otherwise, are you still using the same version of neato as before? Could it be that its output format has changed in some way?
The best way to find out might be to set a debugging break point in the offending line 94 ([node_pos] = sscanf(line(pos_pos:length(line)), ' pos = "%d,%d"')';) and check what line(pos_pos:length(line)) evaluates to.

Octave Errors in attempting to study Image Compression

Let me start by saying I LOVE YOU. Thank you.
Next order of business:
octave-3.2.3:8> xin = imread('3Phone.png');
octave-3.2.3:9> colormap(gray(256));
octave-3.2.3:10> image(xin);
error: invalid value for array property "cdata"
error: set: expecting argument 2 to be a property name
error: set: expecting argument 4 to be a property name
error: set: expecting argument 6 to be a property name
error: called from:
error: /Applications/Octave.app/Contents/Resources/share/octave/3.2.3/m/image/__img__.m at line 57, column 7
error: /Applications/Octave.app/Contents/Resources/share/octave/3.2.3/m/image/image.m at line 75, column 5
error: A(I): Index exceeds matrix dimension.
error: called from:
error: /Applications/Octave.app/Contents/Resources/share/octave/3.2.3/m/plot/__go_draw_axes__.m at line 383, column 22
error: /Applications/Octave.app/Contents/Resources/share/octave/3.2.3/m/plot/__go_draw_figure__.m at line 92, column 3
error: /Applications/Octave.app/Contents/Resources/share/octave/3.2.3/m/plot/gnuplot_drawnow.m at line 91, column 5
octave-3.2.3:10>
I am using Octave 3.2.3 on Mac OS X (Snow Leopard). This is a very basic attempt to display an image that has been read and stored memory. Any help on fixing this problem would be much appreciated. Thanks!
My guess, When you read a png file - Make sure it's a grayscale file.
Otherwise there are 3 Matrices (RGB). Therfore you can't use Gray Colormap.
If 2Phone.png is a color image, Try (At least this is what I would do in Matlab):
xin = imread('3Phone.png');
image(xin(:, :, 1);
colormap(gray(256));
This would display only the R Matrix.
Or better, use RGB2Gray (Of course, use the equivalent of Octave).