dividing value by 100
古いコメントを表示
I want to divide my data by 100
How to do it in MATLAB Analysis ?
data = thingSpeakRead(readChannelID, 'ReadKey', readAPIKey);
data = thingSpeakRead(readChannelID, 'ReadKey', readAPIKey)/100;
should I use write part ?
thingSpeakWrite(writeChannelID, analyzedData, 'WriteKey', writeAPIKey);
1 件のコメント
Image Analyst
2021 年 7 月 18 日
How about
data = data / 100;
回答 (3 件)
wael elsisi
2021 年 7 月 18 日
編集済み: Image Analyst
2021 年 7 月 18 日
1 件のコメント
Image Analyst
2021 年 7 月 18 日
What do you mean by "wired data"? Did it, or did it not, divide your send_windSpeed values by 100?
wael elsisi
2021 年 7 月 18 日
0 投票
1 件のコメント
John D'Errico
2021 年 7 月 18 日
Please don't use an answer to make a comment.
Image Analyst
2021 年 7 月 18 日
編集済み: Image Analyst
2021 年 7 月 18 日
To divide by 100, how about
send_windSpeed = send_windSpeed / 100;
You said you're getting integers. So, in your code
send_windSpeed = thingSpeakRead(readChannelID, 'ReadKey', readAPIKey);
send_windSpeed = send_windSpeed/100;
is send_windSpeed integer or floating point after the first line of code where you call thingSpeakRead()? The second line should not change it from floating point to integer.
To multiply by 100, you simply use * instead of /, like this:
send_windSpeed = send_windSpeed * 100;
Please reply as a comment to this (my) answer, not as a brand new answer to your original question.
24 件のコメント
wael elsisi
2021 年 7 月 18 日
編集済み: wael elsisi
2021 年 7 月 18 日
wael elsisi
2021 年 7 月 18 日
編集済み: wael elsisi
2021 年 7 月 18 日
data = int16(3100)
data = data * 100
data = data / 100
I can't replicate your values. Anyway, int16 cannot handle a value of 310000 so it will clip to 32767.
wael elsisi
2021 年 7 月 18 日
Image Analyst
2021 年 7 月 18 日
Not sure I can do more unless your channel is public and you give me the channel number, readChannelID.
wael elsisi
2021 年 7 月 18 日
Image Analyst
2021 年 7 月 18 日
Please give me code that runs. This code that I tried does not:
readChannelID = 1448319
send_windSpeed = thingSpeakRead(readChannelID, 'ReadKey', readAPIKey)
send_windSpeed = send_windSpeed/100;
It doesn't know what readAPIKey is. Make it easy for us to help you.
Christopher Stapels
2021 年 7 月 19 日
@wael elsisi that call only works for you because you are logged in to ThingSpeak. You need to make the channel public (use the sharing tab on your channel view) or share the read API key.
wael elsisi
2021 年 7 月 19 日
編集済み: wael elsisi
2021 年 7 月 20 日
wael elsisi
2021 年 7 月 22 日
Image Analyst
2021 年 7 月 22 日
You can just divide your arrays by 100 like I already showed you. You can have your thingSpeak program run MATLAB code and do whatever you want.
I'm not a thingSpeak expert and I don't have time to delve into it for you. I suggest you call tech support.
Christopher Stapels
2021 年 7 月 22 日
Now that you have provided a public cahnnel, the original code works. I've added a name value pair to include 3 points. Your data includes some NAN values, dividing NAN by 100 has no effect. For the entries with numbers, the operation worked exactly.
readChannelID = 1450213;
windSpeed = thingSpeakRead(readChannelID, 'numPoints',3);
smallWindSpeed = windSpeed/100;
windSpeed =
NaN NaN
2867 7079
2867 7076
smallWindSpeedSM =
NaN NaN
28.6700 70.7900
28.6700 70.7600
wael elsisi
2021 年 7 月 23 日
Image Analyst
2021 年 7 月 23 日
Replace line 27 by these three lines
fprintf('Before, send_Soil_T(1) = %f.\n', send_Soil_T(1));
send_Soil_T = send_Soil_T / 100;
fprintf('After, send_Soil_T(1) = %f.\n', send_Soil_T(1));
If the value is pure zero, then find some index other than 1 that is not zero.
Now, copy and paste what you see in the command window back here to prove that it is not dividing by 100.
wael elsisi
2021 年 7 月 24 日
Image Analyst
2021 年 7 月 24 日
編集済み: Image Analyst
2021 年 7 月 24 日
Wael - did you see my last comment??? Evidently not because you did not copy and paste anything back here, like what got printed out to the command window.
fprintf('Before, send_Soil_T(1) = %f.\n', send_Soil_T(1));
send_Soil_T = send_Soil_T / 100;
fprintf('After, send_Soil_T(1) = %f.\n', send_Soil_T(1));
wael elsisi
2021 年 7 月 24 日
Image Analyst
2021 年 7 月 24 日
But you didn't show the results. Make sure the command window is showing. Then set a break point the first line after 35 that will let you. Then copy and paste the command window contents back here.
wael elsisi
2021 年 7 月 25 日
Image Analyst
2021 年 7 月 25 日
OK. Glad it's working now. The array is clearly being divided by 100.
wael elsisi
2021 年 7 月 25 日
Image Analyst
2021 年 7 月 25 日
So before it was 3173, and after it is 31.73 and you say nothing has changed? What is your justification for saying that 31.73 is the same as 3173? To everyone else it looks like it's been divided by 100, so why not you?
wael elsisi
2021 年 7 月 25 日
Image Analyst
2021 年 7 月 25 日
Did you replot the data after it was divided by 100? Just dividing the array won't do a replot automatically. That is a separate step you must do explicitly.
コミュニティ
その他の回答 ThingSpeak コミュニティ
カテゴリ
ヘルプ センター および File Exchange で Prepare and Analyze Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




