Community RSS Feed
http://community.wolfram.com
RSS Feed for Wolfram Community showing questions from all groups sorted by newest repliesBSplineFunction not evaluating as expected in RevolutionPlot3D
http://community.wolfram.com/groups/-/m/t/1242827
Hello,
Why does the code (shown below) give this error?
> Dot::rect: Nonrectangular tensor encountered.
And how might this code be modified to produce the desired plot?
controlPoints = {{0., 1.48195}, {0.151384, 1.49651}, {0.330883, 1.39382}, {0.488076, 1.2461}, {0.575162, 1.06331}, {0.599079, 0.886118}, {0.547864,
0.698224}, {0.46997, 0.542705}, {0.386957, 0.404801}, {0.285357, 0.28673}, {0.314028, -0.0307762}, {0.202299, -0.0181826}, {0., 0.}};
RevolutionPlot3D[BSplineFunction[controlPoints][t], {t, 0, 1}]Rian Shams2017-12-11T04:51:43ZHow to refresh or clear cached CloudObjects[]?
http://community.wolfram.com/groups/-/m/t/1242497
[*cross posted on mathematica.stackexchange.com*](https://mathematica.stackexchange.com/q/161661/5478)
Let's create an API which creates one file each time it is called/accessed:
obj = CloudDeploy[
APIFunction[{}
, Put[$RequesterWolframID
, "testFiles/" <> DateString["ISODateTime"] <> ".txt"
] &
]
, "apiTest"
, Permissions -> "Public"
];
CloudEvaluate@CreateDirectory@"testFiles/";
and let's call it:
URLRead[obj]
CloudObjects["testFiles/"]
URLRead[obj]
CloudObjects["testFiles/"]
[![enter image description here][1]][1]
But this is not true, if you visit a browser interface they will be there:
[![enter image description here][2]][2]
In fact, once you visit it, `CloudObjects` cache changes, but only once:
URLRead[obj]
CloudObjects["testFiles/"]
URLRead[obj]
CloudObjects["testFiles/"]
[![enter image description here][3]][3]
So how to make sure `CloudObjects` returns up to date result?
I am fine with an additional step to flush the cache, I just want it to be possible programmatically.
[1]: https://i.stack.imgur.com/jBXTj.png
[2]: https://i.stack.imgur.com/5WLAs.png
[3]: https://i.stack.imgur.com/9zzA7.pngKuba Podkalicki2017-12-10T13:57:17ZGet["..."] and RAM
http://community.wolfram.com/groups/-/m/t/1242224
Hello everybody,
I have a little issue with my RAM during a Do loop. Within this do loop I use Get to open a file and thereafter to manipulate it. The memory used is increased by 120 every time the loop runs. This is not much but since I run the loop for several thousand times this small value accumulates. I could pin it down to the Get function and I have created a minimal example (see below) with all RAM tricks that I know of (although I assume that some of them are - in this case - not even necessary). Does anybody know what to do?
Unprotect[Out];
Unprotect[In];
$HistoryLength = 0;
Do[
Get[stringValueOfTheFile];
ClearSystemCache[];
Clear[In];
Clear[Out];
Print[MemoryInUse[]];
, {i, 1, 100}];
Thanks in advance
MarkusMarkus ThÃ¼rmann2017-12-09T12:27:50ZBug with Block & Lookup: Scope Variable Leak.
http://community.wolfram.com/groups/-/m/t/1241974
After debugging a large chunk of code, I could identify this [MWE](https://en.wikipedia.org/wiki/Minimal_Working_Example).
ClearAll@test
test[var_String]:= Block[{association},
association = <|"x"-> <|"key01"-> "ok"|>|>[var];
Lookup[association,"key01",{}]
]
If I evaluate:
test["x"]
test["y"]
test["x"]
I get an error evaluating the last `test["x"]`. What is very strange, I expected to find an error just in the evaluation of `test["y"]`.
The same error does not occur if we change from Block to Module. In the Block case, we have some sort of unexpected scope leak.
Looks like a bug in `Lookup`.
[Cross post](https://mathematica.stackexchange.com/questions/161616) in Stack ExchangeRodrigo Murta2017-12-08T21:32:33ZHow to export a PNG file with ColorMap and RawData?
http://community.wolfram.com/groups/-/m/t/1241941
Some database for machine learning, like VOC dataset, use .PNG file to store information. They store information in 0~255, and display it by using ColorMap.
I import it by using this code:
data=Import[path, "RawData"]
cmap=Import[path, "ColorMap"]
But I cannot find a way to export a PNG file in this format. A .PNG file in this format is included.Zhang Yanbo2017-12-08T14:38:40ZGetting data from an analog-to-digital converter
http://community.wolfram.com/groups/-/m/t/1241573
I am using the Grove microphone and the Grove analog-to-digital converter to sample sound. The Grove platform documentation provides the following example C code to read data from the ADC that I am trying to port to Mathematica:
#include <Wire.h>
#define ADDR_ADC121 0x55
#define V_REF 3.00
#define REG_ADDR_RESULT 0x00
#define REG_ADDR_ALERT 0x01
#define REG_ADDR_CONFIG 0x02
#define REG_ADDR_LIMITL 0x03
#define REG_ADDR_LIMITH 0x04
#define REG_ADDR_HYST 0x05
#define REG_ADDR_CONVL 0x06
#define REG_ADDR_CONVH 0x07
unsigned int getData;
float analogVal=0; // convert
void init_adc()
{
Wire.beginTransmission(ADDR_ADC121); // transmit to device
Wire.write(REG_ADDR_CONFIG); // Configuration Register
Wire.write(0x20);
Wire.endTransmission();
}
void read_adc() //unsigned int *data
{
Wire.beginTransmission(ADDR_ADC121); // transmit to device
Wire.write(REG_ADDR_RESULT); // get result
Wire.endTransmission();
Wire.requestFrom(ADDR_ADC121, 2); // request 2byte from device
delay(1);
if(Wire.available()<=2)
{
getData = (Wire.read()&0x0f)<<8;
getData |= Wire.read();
}
Serial.print("getData:");
Serial.println(getData);
delay(5);
Serial.print("The analog value is:");
Serial.print(getData*V_REF*2/4096);
Serial.println("V");
}
The code writes 0x20 to 'register 2'. After some trial and error I found out that the Mathematica equivalent seems to be:
DeviceWrite[i2c, {0,0,32}]
because after that I can read data continuously using:
d = DeviceRead[i2c, 2]; n = d[[1]] * 256 + d[[2]]
Is this the way to set 'registers' on an ADC? Also, what does setting it achieve? The Grove documentation is rather vague on this point.
Thanks,
GijsbertGijsbert Wiesenekker2017-12-08T14:29:04ZDynamic List Plot of Serial Input in Mathematica via Arduino Serial.Print()
http://community.wolfram.com/groups/-/m/t/1241353
Hey everybody,
I'm trying to read the serial input of my USB Port into Mathematica dynamically to create a live ListPlot.
My Arduino Uno sends strings in the format of a pair via Serial.print() to the Serial Port:
![\]\[1\]][1]
(the constant Output "{0,1}\n" is just a test value)
In Mathematica 11 I connect to the Serial Port via DeviceOpen[] and start a Task that reads out the Buffer Data on my Arduino and converts it to a string.
Then I split that string into substrings at any "\n" to get pairs and interpret them in Wolfram Language as a pair.
I add these pairs to a list and then Plot that list dynamically via ListLinePlot[].
![\]\[2\]][2]
My Problem is that Mathematica doesn't read that data correctly and mostly mashes up the data and crashes.
It would be great if you guys could help me out with that!
Thanks!
[1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=arduino.JPG&userId=1241339
[2]: http://community.wolfram.com//c/portal/getImageAttachment?filename=8486signaltransfer.JPG&userId=1241339Franz Biermann2017-12-07T18:41:19Zinterpolation command
http://community.wolfram.com/groups/-/m/t/1240993
Hello,
Is there any way to vary interpolation or adding specific number to eliminate unwanted points. For example, in my case the arrows in the opposite direction. In other words, what I should add in this: Interpolation[data]
In[5]:= data = MapThread[{{#1, #2}, #3} &, {z, x, ffun}]
Out[5]= Out[5]
In[6]:= q = Interpolation[data]
Out[6]= InterpolatingFunction[{{0.336, 0.352}, {0.439, 0.455}}, <>]
In[7]:= gradient[a_, b_, i_] :=
Evaluate[Grad[q[a[[i]], b[[i]]], {a[[i]], b[[i]]}]]
In[8]:= gr =
Reap[Do[Sow[{z[[i]], x[[i]], gradient[z, x, i]}], {i,
Length[z]}]][[-1, 1]]
Out[8]= Out[8]
In[9]:= vunorm = Im[gr[[;; , 3]]];
In[10]:= vn = Normalize /@ vunorm;
In[11]:=
vnn = Table[{z[[i]], x[[i]], vn[[i]]}, {i, 1, Length[vn]}]
Out[11]= Out[11]
In[12]:= list = Partition[Flatten[vnn], 4];
In[13]:= vl =
ListVectorPlot[list, VectorScale -> Small, VectorPoints -> {25, 25}]
For more details, please see the attachment.
Many thanks in advance!Ghady Almufleh2017-12-06T15:46:13ZAvoid an element identification problem from a matrix in a "For" loop ?
http://community.wolfram.com/groups/-/m/t/1238453
Dear Friends,
I am struggling with a minor looking problem and could not figure out a solution. Looking forward for any help. Attached is the *.nb file containing my code. Followings are the important points
1. In the beginning of the code I have defined a six element table (blue font in *.nb file)
f[m_] := Table[f[m, n], {n, 1, 6}];
and the elements of f[0] are given as follows (magenta color in *.nb file)
f[0, 1] = f[0, 2] = f[0, 3] = f[0, 4] = f[0, 5] = f[0, 6] = 1/6;
2- In the end of the code, there is a "For" loop to determine f[m] for m > 0
Ignoring the other mathematical complexities, for determine each f[m], elements of f[m-1] are required to fed in DSC3[m] (substitutions shown in red color).
3- The loop works fine for first cycle of m = 1 since elements of f[0] are defined initially as f[0, 1]....etc and I get f[1] = {1/3,0,1/6,1/6,1/6,1/6}.
4- Though the second cycle for m = 2 does not work as when I ask (red color in *.nb file)
{f[m, i] -> 0, f[m, j] -> f[m - 1, j] + f[m - 1, i], f[m, x_] -> f[m - 1, x]}
Mathematica does not recognize that f[m-1, j] is jth element of f[m-1] and does not take its value from the o/p of m = 1 cycle (f[1]).
In addition, if I try to tell mathematica separately that f[m, n] = f[m][[n]], I get the error message -
*$RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of ...*
Will be greatful for any suggestion to this problem
thanksS G2017-12-04T07:07:35Z