I want to open a text file in scilab then count the frequence of each character of ASCII code.
So this is the script I use :
m=mgetl("Texte.txt")
m=strsubst(m," ","");
m=ascii(m);
format(5)
for i=1:26
f(i)=frequence(i+64,m);
if f(i)<>0 then
afficher("La fréquence de ..
"+string(ascii(i+64))+" est "+string(f(i)))
end
end
But i get this error : frequence is not defined. it is supposed to be used in scilab as a function. I am using scilab version 5.5.0
Thank you
You could use dsearch.
m=mgetl("Texte.txt")
m=strsubst(m," ","");
m=ascii(strsplit(strcat(string(m))));
bins = (1:26)+64
[i_bin, counts, outside] = dsearch(m, bins,"d")
for i=1:26
printf("%s : %d\n", ascii(bins(i)), counts(i))
end
Related
I am working on a verilog code. I am completely new to verilog.
Suppose, I have to represent 0.6072529350088814 in hexadecimal, its value comes out to be 32'h26dd3b6a, as shown in code on the below :
https://electronics.stackexchange.com/questions/354594/cordic-algorithm-using-verilog
But I donot understand how this conversion works?
Suppose I want to display the value and see it in decimal, what should be code?
`timescale 1ns / 1ps
module top(
);
wire signed[31:0] init_value= 32'h26dd3b6a; // 0.6072529350088814
always#(*)
begin
$display("The init_value= %d", init_value);
end
endmodule
I have tested the above line of code, but this does not work.
The value of the init_value is displayed as
The init_value= 652032874
I expect that result should be 0.6072529350088814.
Code:
$display("The init_value = %f", $itor(init_value) / (2 ** 30));
Prints:
The init_value = 0.607253
I am not sure if the code under the link is correct. Theoretically, the conversion should be done through 2 ** 31 or 2 ** 32.
can anybody help me with solving my problem of Hex2Bin and Bin2Hex functions?
First I was trying to make the conversion Hex2Bin. I would like to call the AddIn function from macro so I called createUNOservice:
Function fcHex2Bin(arg as variant, NumberOfBits As integer) as string
Dim oService as Object
oService = createUNOService("com.sun.star.sheet.addin.Analysis")
sArg = cStr(arg)
fcHex2Bin = oService.getHex2Bin(sArg,NumberOfBits)
End Function
but all the time ends with fault message like "The object variable is not set.". I already don't know why.
My final goal would be to make all functions of Calc running in macros, but at this moment I would be glad to have two functions Hex2Bin and Bin2Hex running - anyhow.
My LibreOffice version:
Version: 7.1.3.2 (x64) / LibreOffice Community
Build ID: 47f78053abe362b9384784d31a6e56f8511eb1c1
CPU threads: 8; OS: Windows 10.0 Build 19042; UI render: Skia/Raster; VCL: win
Locale: cs-CZ (cs_CZ); UI: cs-CZ
Calc: CL
Thank you for your help.
This way works.
Function fcHex2Bin(aNum As String, rPlaces As Any) As String
Dim oFunc As Object
oFunc = CreateUnoService("com.sun.star.sheet.FunctionAccess")
Dim aArgs(0 to 1) As Variant
aArgs(0) = aNum
aArgs(1) = rPlaces
fcHex2Bin = oFunc.callFunction("com.sun.star.sheet.addin.Analysis.getHex2Bin", aArgs())
End Function
As for why the other way does not work, many analysis functions require a hidden XPropertySet object as the first argument. The following code produces informative error messages:
REM IllegalArgumentException: expected 3 arguments, got 1
sResult = oService.getHex2Bin(ThisComponent.getPropertySetInfo())
REM IllegalArgumentException: arg no. 0 expected: "com.sun.star.beans.XPropertySet"
sResult = oService.getHex2Bin(ThisComponent.getPropertySetInfo(), "2", 4)
However I tried passing ThisComponent.getPropertySetInfo().getProperties() from a Calc spreadsheet and it still didn't work, so I'm not exactly sure what is required to do it that way.
The documentation at https://help.libreoffice.org/latest/he/text/sbasic/shared/calc_functions.html does not really explain this. You could file a bug report about missing documentation, perhaps related to https://bugs.documentfoundation.org/show_bug.cgi?id=134032.
I have a multidimensional string vector, gameState. The contents of gameState can be seen below. I would like to "move" A up one space by making [2][1] = " " and [1][1] = "A". But I'm getting an error (error: invalid conversion from 'const char*' to '__gnu_cxx::__alloc_traitsstd::allocator<char, char>::value_type' {aka 'char'} [-fpermissive]). Not sure if there is a way to use vector.at() in this case. Here is a snippet. The full code reads in the initial game state from a text file and assigns it to the string vector gameState. I get the row and col indexes for each letter in the grid below and assign them to variables (eg. Arow and Acol). I'm very new to C++, so any help would be appreciated. If you have any questions about the rest of the code, I'd be happy to elaborate. Thanks in advance.
int Arow;
int Acol;
vector<string> gameState;
string tempU = gameState[Arow-1][Acol];
if (tempU != "#") {
// if no wall is up, move up
gameState[Arow][Acol] = " ";
gameState[Arow-1][Acol] = "A";
Arow = Arow-1;
Amovesequence.push_back("U");
}
###########
#...#P...B#
#A#.$.###*#
#...#D...R#
###########
The type of gameState[Arow-1][Acol] is a char, not a string. Modify the code accordingly, e.g.: char tempU = ... and replace " " with ' 'etc.
I've been looking around for a while so forgive me if maybe I'm using improper terminology...
The goal of the code is to update Aout1 and Aout0 if the input is 0, with the output corresponding to a 7-segment display, but I'm getting the following error:
"Error (10170): Verilog HDL syntax error at FourBitAdder.v(55) near text: ","; expecting ";". Check for and fix any syntax errors that appear immediately before or at the specified keyword."
Below is a snippet of the code giving me issues...
always #*
case (A)
4'b0000 : Aout1 = 7'b1000000, Aout0 = 7'b1000000; //00
I tried changing the code to the following and while I didn't get any errors on my software, my hardware (7-segment display) isn't working like it was when I was trying to just change one variable per case.
always #*
case (A)
4'b0000 : Aout1 = 7'b1000000; 4'b0000 : Aout0 = 7'b1000000; //00
Thank you in advance :)
Use a begin and end statement after the colon.
always #* begin
case(A)
4'b0000: begin
Aout1 = 7'b1000000;
Aout0 = 7'b1000000;
end
4'b0001: begin
Aout1 = 7'b0000011;
Aout0 = 7'b0000011;
end
endcase
end
So I'm trying to print out hex values in c++ using printf, and well, I want the output of the following string to be val:0x0366 including that leading 0
Here's the code
int poo = 0x00000366;
printf("val:0x%x \n",poo);
Here's the output:
0x366
Have you tried printf("val:0x%04x \n",poo);?
According to printf reference,
A format specifier follows this prototype:
%[flags][width][.precision][length]specifier
In your case:
%[0][4][default precision][default lenght]x